The Artima Developer Community
Sponsored Link

Java Buzz Forum
Inheritance interview programming questions : Part 2

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Inheritance interview programming questions : Part 2 Posted: Feb 15, 2016 11:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Inheritance interview programming questions : Part 2
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement

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. }



Click for Output


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. }


Click for Output


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. }


Click for Output


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. }


Click for Output




Read: Inheritance interview programming questions : Part 2

Topic: MVC 1.0 in Java EE 8: Getting started using facelets Previous Topic   Next Topic Topic: Find second highest number in integer Array

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use