I created a class named A
and put this code under this class. I created a subclass named B
under the same file.
package com.puneetred.sem3;
class A extends B {
public static void methodB() {
System.out.println("Second Class");
}
public static void main(String[] args) {
methodA();
methodB();
}
}
public class B {
public static void methodA() {
System.out.println("First class");
}
}
Compiling the above code throws this exception:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at com.puneetred.sem3/com.puneetred.sem3.B.methodA(A.java:18)
at com.puneetred.sem3/com.puneetred.sem3.A.main(A.java:10)
But when I remove the public
keyword before class B
, the code just runs fine.