Instructions:
1.)Save this program to a file and name it Inheritance.java
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import javax.swing.JOptionPane; class SuperClass //The Superclass { String str="We Got Copieeed!!!"; void func() { JOptionPane.showMessageDialog(null, str); //Prints the string 'str' in a window. } } class SubClass extends SuperClass //The SubClass inheriting SuperClass { } public class Inheritance { public static void main(String[] args) //Our main { SubClass sub1= new SubClass(); //SubClass Object Initialization. sub1.func(); //Call to function of SuperClass via object of the Subclass } } |
Tested in compilers: Eclipse and Command Line.
Lalit Mali
Lalit is a technology enthusiast, a programming lover and currently an Android fan.
Latest posts by Lalit Mali (see all)
- Rank Pages in a Directory by Occurrence of a Particular Word in them – Java Data Mining - October 16, 2012
- Java Data Mining: Number of occurrences of a word in a file - October 15, 2012
- Calculate factorial of a number using C++ Recursive function - October 14, 2012