Instructions:
1.)Save this program to a file and name it Inheritance.java
Tested in compilers: Eclipse and Command Line.
Labels:
Java
1.)Save this program to a file and name it Inheritance.java
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 } }
Responses
0 Respones to "Program to Demonstrate Inheritance in Java"
Post a Comment