In the class level, I've created methods and declared variables. When I'm calling the methods in the main method, it's throwing an error as :
No enclosing instance of type HirachyInha is accessible. Must qualify the allocation with an enclosing instance of type HirachyInha (e.g. x.new A() where x is an instance of HirachyInha).
package day11;
public class HirachyInha {
class Parent {
void display(int a) {
System.out.println(a);
}
}
class Child1 extends Parent {
void show(int b) {
System.out.println(b);
}
}
class Child2 extends Parent {
void print(int c) {
System.out.println(c);
}
}
public static void main(String[] args) {
Child1 child1 = new Child1();
child1.display(100);
child1.show(200);
}
}
Not understanding why am getting an error while calling the methods from main method.
use the keyword static with the inner classes. that should take care of this particular problem.