Proxy > Gmail Facebook Yahoo!

Program to Demonstrate Inheritance in Java



Instructions:
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
 }
 
}
Tested in compilers: Eclipse and Command Line.


Responses

0 Respones to "Program to Demonstrate Inheritance in Java"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar