Sunday, May 12, 2019

what is the output of the program?

Problem statement:
what is the output of the following code?
  1. public class A {
  2.     public static void showMe() {
  3.         System.out.println("A");
  4.     }
  5. }
  6. class B extends A {
  7.     public static void showMe() {
  8.         System.out.println("B");
  9.     }
  10. }
  11. class C extends B {
  12.     public static void showMe() {
  13.         System.out.println("C");
  14.     }
  15. }
  16. class Main {
  17.     public static void main(String[] args) {
  18.         A a = new B();
  19.         a.showMe();
  20.         A a1 = new A();
  21.         a1.showMe();
  22.         B b = new C();
  23.         b.showMe();
  24.         C c = new C();
  25.         c.showMe();
  26.     }
  27. }
Output:
A
A
B
C

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...