logo

Crowdly

What is the output of the following program? class  Parent {        String n...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

What is the output of the following program?

  1. class Parent {   
  2.     String name;   
  3.     
  4.     void showMessage()   

  5.     {   
  6.         System.out.println("Parent method is called");   
  7.     }   
  8. }   
  9. class Child extends Parent {   

  10.     int age;   
  11.     
  12.     @Override  

  13.     void showMessage()   
  14.     {   
  15.         System.out.println("Child method is called");   
  16.     }   
  17. }   
  18.     
  19. public class Downcasting{  
  20.     
  21.     public static void main(String[] args)   
  22.     {   
  23.         Parent p = new Child();  
  24.         p.name = "Adrian";  
  25.       
  26.         Child c = (Child)p;   
  27.         c.age = 18;   
  28.         System.out.println(c.name);   
  29.         System.out.println(c.age);   
  30.         c.showMessage();   
  31.     }   
  32. }  
More questions like this

Want instant access to all verified answers on moodle.medtech.tn?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!