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
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. package interviewprograms.instanceofjava; public class Super{ int a, int b; void show(){ System.out,println("Inside Show method"); } } package interviewprograms.instanceofjava; public class Sub extends Super{ int a, int b; public static void main(String[] args) { Super obj= new Super(); obj.a=10; System.out,println(obj.a); obj.show(); } } 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. package interviewprograms.instanceofjava; public class Super{ int a, int b; void show(){ System.out,println("Inside Show method"); } } package interviewprograms.instanceofjava; public class Sub extends Super{ int x; void show(){ System.out,println("Inside Sub class Show method"); } public static void main(String[] args) { Sub obj= new Sub (); obj.x=10; System.out,println(obj.x); obj.show(); } } Click for Output
10 Inside Sub class Show method 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. package interviewprograms.instanceofjava; public class Super{ int a, int b; void show(){ System.out,println("Inside Show method"); } void print(){ System.out,println("Inside super class print method"); } } package interviewprograms.instanceofjava; public class Sub extends Super{ int x; void show(){ System.out,println("Inside Sub class Show method"); } void msg(){ System.out,println("Inside Sub class msg method"); } public static void main(String[] args) { Sub obj= new Sub (); obj.x=10; System.out,println(obj.x); obj.show(); obj.print(); } } Click for Output
10 Inside Sub class Show method Inside super class print method Program #4: core java online test for beginners and experienced on inheritance Creating object for sub class and assigning to super class reference. package interviewprograms.instanceofjava; public class Super{ int a, int b; void show(){ System.out,println("Inside Show method"); } void print(){ System.out,println("Inside super class print method"); } }
Click for Output
Inside Sub class Show method 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. package interviewprograms.instanceofjava; public class Super{ int a, int b; void show(){ System.out,println("Inside Show method"); } void print(){ System.out,println("Inside super class print method"); } } package interviewprograms.instanceofjava; public class Sub extends Super{ int x; void show(){ System.out,println("Inside Sub class Show method"); } void msg(){ System.out,println("Inside Sub class msg method"); } public static void main(String[] args) { Super obj= new Sub (); obj.msg(); } } Click for Output
Compile time error : The method msg() is undefined for the type Super EnJoY LeArNinG WitH Us...
Read: Core java online programming test on inheritance