Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

why to declareSuperclass in another file?

807598Oct 24 2006 — edited Oct 24 2006
i am having an error in the following program.plz tell me why.

public class Superclass
{
public void ss()
{
System.out.println("Hello World!from subclass");
}


}
public class Subclass extends Superclass
{
public static void main(String[] args)
{
System.out.println("Hello World!");
Superclass su = new Superclass();
su.ss();

}
}

the error it is giving is:
class Superclass is public,should be declared in a file named Superclass.java.

i am not getting the error if i change the accessibility to default.is it a error to declare both the classes as public.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 21 2006
Added on Oct 24 2006
1 comment
80 views