Search This Blog

Tuesday, 28 January 2014

Inheritance Demo

/* Simple program to illustrate Inheitance in java */


package inheritanceexample;

class ParentOne
{
    public int Add(int a,int b,int c)
    {
        return a+b+c;
    }
    public float Sub(float a,int b)
    {
        return a-b;
    }
}

class Child extends ParentOne
{
    
}

class MainClass
{
    public static void main(String[] args)
    {
        Child c=new Child();
        
        int resAdd=c.Add(2,3,4);
        float resSub=c.Sub(3,2);
        System.out.println("Addition is :"+resAdd);
        System.out.println("Subtration is :"+resSub);
    }
}

output


Addition is :9
Subtration is :1.0

No comments:

Popular Posts