Sunday, 16 September 2012

Java program codes: inheritance in java

inheritance in java

class A{
    public void fun1(int x){
        System.out.println("Int in A is :" + x);
        }
    }
class B extends A{
    public void fun2(int x,int y){
        fun1(6);  // prints "int in A"
        System.out.println("Int in B is :" + x + " and " + y);
        }
    }
public class inherit{
    public static void main(String[] args){
        B obj=new B();
        obj.fun2(2, 5);
        }
}

output
Int in A is: 6
Int in B is: 2 and 5

No comments:

Post a Comment