Class x public x int i System out println 1 class Y extends x public Y System out println 2

Question: Following code is showing compile time error. Can you identifythe error?class X{//Class X Members}class Y{//Class Y Members}class Z extends X, Y{//Class Z Members}Answer:In Java, a class can not extend more than one class. Class Z is extending twoclasses – Class X and Class Y. It is a compile time error in java.

Question: What will be the output of following program?15/20

class A{int i = 10;}class B extends A{int i = 20;}public class MainClass{public static void main(String[] args){

Get answer to your question and much more

Question: What will be the output of the below program?16/20

Get answer to your question and much more

Question: How to identify super and invocation hierarchy ?17/20

Get answer to your question and much more

Question: What is the invocation flow in following example ?18/20

class A{static{System.out.println("THIRD");}}class B extends A{static{System.out.println("SECOND");}}class C extends B{static{System.out.println("FIRST");}}public class MainClass{public static void main(String[] args){C c = new C();}}Answer:THIRD SECOND FIRSTQuestion: Where super() or this() should be located?public class A{public A(){System.out.println(1);super();System.out.println(2);

Get answer to your question and much more

Question: Can you identify the member visibilty error in this code ?19/20

class X{private int m = 48;}class Y extends X{void methodOfY(){System.out.println(m);}}Answer:Because, private field ‘m’ is not visible to class Y.Keys to interview successYou must understand that knowing the OOP concepts is the key to successful interview.You will be asked questions about inheritance, abstraction, and interfaces. No technicalinterview is complete without questions on these topics. And the best way to prepare forthem is to understand the core concepts.They are also important in interview assignments or are often asked in the telephonicinterviews.So make sure you have a sound understanding of the concepts presented above.About The AuthorReferences--which-one should-you-choose-.html20/20

It happens because you don't override the method 'proc' in Z class. When you overriding the method, you can't use argument, which has a child class of original argument class. If you add @Override on Z.proc(Z p), your code will be not compiled.

Let's imagine that it is possible, then you can use some method from Z class during executing Z.proc(Z p).

class Z extends Y {
    public Z() {
        v += 9;
    }

    public void proc(Z p) {
        someActions();
        System.out.println(39);
    }

    private void someActions() {
        System.out.println("Some actions");
    }

}

Now when you executing

X x = new Z();
x.proc(new X());

What should happens? There is no 'someActions' method in the X class. How it should works? That's why Z.proc(Z p) doesn't override X.proc(X p). Class Z, has two different methods: Z.proc(Z p) and Y.proc(X p).

When you calling

X x = new Z();
x.proc(new Z());

JVM looks for closest overrided or original method with signature 'proc(X)' to Z class (because X class has 'proc(X)' method) finds it in Y class and executing Y.proc(x p). That's why you see '57' in output.