The Artima Developer Community
Sponsored Link

Java Buzz Forum
Core java online programming test on inheritance

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.
Core java online programming test on inheritance Posted: Jul 17, 2016 1:03 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Core java online programming test on inheritance
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
  • Inheritance means getting properties from one class object to another.
  • So in sub class we can use or access super class variables and method : re usability
  • There are some interesting and important points to discuss about inheritance
  • In major java interviews and java online test on core java there is more chance of getting programming questions from inheritance
  • So let us see some java test questions. java test online to practice
  • If you want explanations then visit below topic
  • Top 16 Java Inheritance Interview questions for freshers and experienced  




5 Points to know about inheritance:

Program #1: Java test on inheritance:
  • Creating object for super class and calling super class methods and accessing super class variables.

  1. package interviewprograms.instanceofjava;
  2. public class Super{
  3.  
  4.  int a, int b;
  5.  
  6. void show(){
  7.  System.out,println("Inside Show method");
  8. }
  9.  
  10. }



  1. package interviewprograms.instanceofjava;
  2. public class Sub extends Super{
  3.  int a, int b;
  4. public static void main(String[] args) {
  5.         
  6. Super obj= new Super();
  7. obj.a=10;
  8. System.out,println(obj.a);
  9.  obj.show();
  10. }
  11. }


Click for Output



Program #2: Core Java online test on inheritance:
  • Creating object for sub class and calling sub class methods and accessing sub class variables.

  1. package interviewprograms.instanceofjava;
  2. public class Super{
  3.  
  4.  int a, int b;
  5.  
  6. void show(){
  7.  System.out,println("Inside Show method");
  8. }
  9.  
  10. }

  1. package interviewprograms.instanceofjava;
  2.  
  3. public class Sub extends Super{
  4.  int x;
  5.  
  6.  
  7. void show(){
  8.  System.out,println("Inside Sub class Show method");
  9. }
  10. public static void main(String[] args) {
  11.         
  12. Sub obj= new Sub ();
  13. obj.x=10;
  14. System.out,println(obj.x);
  15.  obj.show();
  16. }
  17. }


Click for Output


Program #3: core java online test for beginners and experienced on inheritance
  • Creating object for sub class accessing super class members and sub class members.

  1. package interviewprograms.instanceofjava;
  2. public class Super{
  3.  
  4.  int a, int b;
  5.  
  6. void show(){
  7.  System.out,println("Inside Show method");
  8. }
  9.  
  10. void print(){
  11.  System.out,println("Inside super class print method");
  12. }
  13.  
  14. }

  1. package interviewprograms.instanceofjava;
  2.  
  3. public class Sub extends Super{
  4.  int x;
  5.  
  6.  
  7. void show(){
  8.  System.out,println("Inside Sub class Show method");
  9. }
  10. void msg(){
  11.  System.out,println("Inside Sub class msg method");
  12. }
  13. public static void main(String[] args) {
  14.         
  15. Sub obj= new Sub ();
  16. obj.x=10;
  17. System.out,println(obj.x);
  18.  obj.show();
  19. obj.print();
  20. }
  21. }


Click for Output




Program #4: core java online test for beginners and experienced on inheritance
  • Creating object for sub class and assigning to super class reference.

  1. package interviewprograms.instanceofjava;
  2. public class Super{
  3.  
  4.  int a, int b;
  5.  
  6. void show(){
  7.  System.out,println("Inside Show method");
  8. }
  9.  
  10. void print(){
  11.  System.out,println("Inside super class print method");
  12. }
  13.  
  14. }


core java online test for beginners



Click for Output


Program #5: core java online test for beginners and experienced on inheritance

  • Creating object for sub class and assigning to super class reference and calling sub class method.
  1. package interviewprograms.instanceofjava;
  2. public class Super{
  3.  
  4.  int a, int b;
  5.  
  6. void show(){
  7.  System.out,println("Inside Show method");
  8. }
  9.  
  10. void print(){
  11.  System.out,println("Inside super class print method");
  12. }
  13.  
  14. }


  1. package interviewprograms.instanceofjava;
  2.  
  3. public class Sub extends Super{
  4.  int x;
  5.  
  6.  
  7. void show(){
  8.  System.out,println("Inside Sub class Show method");
  9. }
  10.  
  11. void msg(){
  12.  System.out,println("Inside Sub class msg method");
  13.  
  14. public static void main(String[] args) {
  15.         
  16. Super obj= new Sub (); 
  17. obj.msg();
  18. }
  19. }


Click for Output


EnJoY LeArNinG  WitH Us...

Read: Core java online programming test on inheritance

Topic: 63% off Gadget Guard iPhone 6 Plus Screen Protector - Deal Alert Previous Topic   Next Topic Topic: From Pig to Spark: An Easy Journey to Spark for Apache Pig Developers

Sponsored Links



Google
  Web Artima.com   

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