Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

  1. Home

Write a program in java for illustrating inheritance

Write a program in java for illustrating inheritance

package A;
import java.io.*;
class x{
    int i,j;
    void showij(){
        System.out.println("i and j"+i+ " " +j);
          }}
         class y extends x{
          int k;
         void showk(){
         System.out.println("k:" +k);
          }
          void sum(){
          System.out.println("i+j+k:" +(i+j+k));
          }}
/** * * @author Student */
public class A {
    /** * @param args the command line arguments     */
    public static void main(String[] args) {
        x ob1=new x();
        y ob2=new y();
ob1.i=10;
ob1.j=20;
System.out.println("contents of superob:");
ob1.showij();
System.out.println();
ob2.i=7;
ob2.j=8;
ob2.k=9;
System.out.println("contents of subob:");
ob2.showij();
ob2.showk();
System.out.println();
System.out.println("sum of i,j and k in subob:");
 ob2.sum();  

 }

Output


Previous
Next Post »