main Method placed in another class rather than the program's starting class
Suppose I create a java program named as Test1.java. In this I added two classes Test1 and Test2.
If I place main method in Test2 class then it will give a runtime error like "main method not found in test1 class".
For Example: -
class test1
{
public static void display()
{
System.out.println("Inside Test1 Class");
}
}
class test2
{
public static void main(String args[])
{
System.out.println("Inside Test2 class");
test1.display();
}
}
Solution: Save the above program with test2.java then compile and run.
Comments
Post a Comment