Problem statement:
what is the output of the following code?
what is the output of the following code?
- public class A {
- public static void showMe() {
- System.out.println("A");
- }
- }
- class B extends A {
- public static void showMe() {
- System.out.println("B");
- }
- }
- class C extends B {
- public static void showMe() {
- System.out.println("C");
- }
- }
- class Main {
- public static void main(String[] args) {
- A a = new B();
- a.showMe();
- A a1 = new A();
- a1.showMe();
- B b = new C();
- b.showMe();
- C c = new C();
- c.showMe();
- }
- }
Output:
A
A
B
C
No comments:
Post a Comment