1. what is the output of following program:

  1. package com.instanceofjava;
  2.  
  3. public class SuperDemo{

  4. public void show(){
  5.  
  6.   System.out.println("Super class show() method called");
  7.  
  8. }
  9.  
  10. }

  1. package com.instanceofjava;
  2. public class SubDemo extends SuperDemo{

  3. public void show(){
  4.  
  5.  System.out.println("Sub class show() method called");
  6.  
  7. }
  8.  public static void main(String args[]){
  9.  
  10. SuperDemo supobj= new SuperDemo();
  11.  supobj.show(); 
  12.  
  13. }
  14. }






2. what is the output of following program:

  1. package com.instanceofjava;
  2.  
  3. public class SuperDemo{

  4. public void show(){
  5.  
  6.   System.out.println("Super class show() method called");
  7.  
  8. }
  9.  
  10. }



  1. package com.instanceofjava;
  2. public class SubDemo extends SuperDemo{

  3. public void show(){
  4.  
  5.  System.out.println("Sub class show() method called");
  6.  
  7. }
  8.  public static void main(String args[]){
  9.  
  10. SuperDemo supobj= new SuperDemo();
  11.  supobj.show(); 
  12.  
  13.  SubDemo subobj=new SubDemo();
  14.  subobj.show();
  15.  
  16.  }
  17. }





3. what is the output of following program:

  1. package com.instanceofjava;
  2.  
  3. public class SuperDemo{

  4. public void show(){
  5.  
  6.   System.out.println("Super class show() method called");
  7.  
  8. }
  9.  
  10. }

  1. package com.instanceofjava;
  2. public class SubDemo extends SuperDemo{

  3. public void show(){
  4.  
  5.  System.out.println("Sub class show() method called");
  6.  
  7. }
  8.  public static void main(String args[]){
  9.  
  10. SuperDemo supobj= new SubDemo();
  11. supobj.show(); 
  12.  
  13. }
  14. }





4. what is the output of following program:

  1. package com.instanceofjava;
  2.  
  3. public class SuperDemo{

  4. public void show(){
  5.  
  6.   System.out.println("Super class show() method called");
  7.  
  8. }
  9.  
  10.  public void superMethod(){
  11.  
  12.         System.out.println("Super class superMethod() called");
  13.  
  14. }
  15.  
  16. }

  1. package com.instanceofjava;
  2. public class SubDemo extends SuperDemo{

  3. public void show(){
  4.  
  5.  System.out.println("Sub class show() method called");
  6.  
  7.  
  8. public void subMethod(){
  9.         System.out.println("Sub class subMethod() called");
  10. }

  11.  public static void main(String args[]){
  12.  
  13. SuperDemo supobj= new SubDemo();
  14. supobj.superMethod();
  15.  
  16. // supobj.subMethod();  // compile time error: The method subMethod() is undefined for the
  17. type Super

  18.  ((SubDemo)supobj).subMethod();
  19. ((SuperDemo)supobj).show();
  20. }
  21. }







Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu