Originally posted by sarang:
What is exactly a Top level Class? As per my understanding
the class after which java file is named.
I tried this:
abstract class myclass
{
public void amethod();
public static void main(String[] args)
{
System.out.println("Just a test");
}
}
class1 extends myclass
{
public void amethod()
{
System.out.println("I am in subclass");
}
}
I named my file as myclass.java
Program compiles fine.But at runtime doesn't find main method?
Can someone explain why? And if that is true how can abstract class be top level class?
Top Level class is any class which can be instanciated, it doesn't necessarily have to be the one that is the file name. You can have multiple classes defined in a single source file, however only one can be coderanch. This also means that you can have multiple top level classes and multiple abstract classes.
Save the following in a file called myclass.java and compile it
then run class1 and class2 and see the results.
class1 and class2 are examples of a Top Level Class, you can create n object with these. myclass and myclass2 are not top level classes since they are absract and you can not create an object directly.