user3449656 user3449656 - 1 year ago 107
Java Question

What does local instructions mean in java?

What does "local instruction" mean in java ,,i see this example and i understand the inheritance but i need clarification about local instruction .

class javafunc {

public static void main(String aa[]) {

javafunc e = new javafunc ();
B b = new E (); //local instruction
b.print ();


class B {

public void print() {

System.out.println("In B");


class E extends B {

public void print() {

System.out.println("In E");

Answer Source

Well this is a case of method overriding. You can see that both of your parent class(Class B) and child class(Class E) have the same method "void print()". So, what do you think, which method will should run? print in class B or print in class E. Class E method will run even it's inheriting from its parent class.

    B b = new E (); // B reference but E object

Even you are creating reference variable for "B" the method in Class E runs. This is because during runtime JVM runs the method specified for the object. And about your //local instruction, I don't know about that but the line means that you are creating a reference variable "b" of type "B" for the "E" object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download