class a // superclass
{
void add()
{
int a,b,c;
a=10;
b=20;
c=a+b;
System.out.println(c);
}
};
// creating a subclass
class b extends a
{
void sub()
{
int a,b,c;
a=10;
b=20;
c=a-b;
System.out.println(c);
}
};
class demo
{
public static void main(String[] args)
{
b b1; // by object of subclass we can access member of superclass.
b1 = new b();
b1.add();
b1.sub();
}
}
No comments:
Post a Comment