Java Example Pool Questions

Asked 2 years ago, Updated 2 years ago, 31 views

class X { 
    public void f( ) { System.out.print("1"); }
    public static void g() { System.out.print("2"); }
}

class Y extends X{
    public void f( ) { System.out.print("3"); }
}

class Z extends Y {
    public static void g( ) { System.out.print("4"); }
}


public class num23 {

    public static void main(String args[]) {
        X obj = new Z( );
        obj.f( );
        obj.g( );
    }
}

obj.f(): Call f( ) in class Z, call f( ) in class parent and output 3

obj.g(): Call g( ) of class Z and output 4

Output result: 34

I solved it in the same format as above, and the answer was 32.

If so

java

2022-09-20 09:47

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.