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 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 method called");
  6.  
  7. }
  8.  public static void main(String args[]){
  9.  SubDemo subobj=new SubDemo();
  10.  subobj.show();
  11. }







2. what is the output of following program:

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

  4.  int x;

  5. }

  1. package com.instanceofjava;
  2. public class SubDemo extends SuperDemo{
  3.  
  4.  int y;
  5.  
  6. public void show(){
  7.  
  8.  super.x=y+2;
  9.   System.out.println("x="+super.x+"y="+y);
  10.  
  11. }
  12.  
  13.  public static void main(String args[]){
  14.  
  15.  SubDemo subobj=new SubDemo();
  16.  subobj.show();
  17.  
  18. }




3. what is the output of following program:

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

  4.  int x;

  5. }

  1. package com.instanceofjava;
  2.  
  3. public class SubDemo extends SuperDemo{
  4.  
  5.  int y;
  6.  
  7. public void show(){
  8.  
  9.  super.x=y+2;
  10.   System.out.println("x="+super.x+"y="+y);
  11.  
  12. }
  13.  
  14.  public static void main(String args[]){
  15.  
  16.  SubDemo subobj=new SubDemo();
  17.  subobj.x=2;
  18.  subobj.y=2;
  19.  subobj.show();
  20.  
  21. }




4. what is the output of following program:

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

  4.  int x;
  5. SuperDemo(){
  6.  
  7.  x=24;

  8. }
  9. }

  1. package com.instanceofjava;
  2. public class SubDemo extends SuperDemo{
  3.  
  4.  int y;
  5.  
  6. public void show(){
  7.  
  8.   System.out.println("x="+super.x);
  9.   System.out.println("y="+y);
  10.  
  11. }
  12.  
  13.  public static void main(String args[]){
  14.  
  15.  SubDemo subobj=new SubDemo();
  16.  subobj.show();
  17.  
  18. }





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

2 comments for Inheritance programming interview questions

Select Menu