Can we override inner class like a method?

no, An inner class cannot be overriden like a method.

example:

class A {
private InnerA y;
protected class InnerA {
public InnerA() { System.out.println(“A.InnerA()”); }
}
public A() {
System.out.println(“New A()”);
y = new InnerA();
}
}

class B extends A {
public class InnerB {
public InnerB() { System.out.println(“B.InnerB()”); }
}
}

public class MainClass{
public static void main(String[] args) {
new B();
}
}