An Java program using inheritance :
class BaseA
{
public BaseA(){
System.out.println("Base A constructor");
}
public void methodOne(){
System.out.println("Method one in base A");
}
}
class BaseB extends BaseA{
public BaseB(){
super();
System.out.println("Base b constructor");
}
public void methodOne(){
BaseA ba=new BaseA();
ba.methodOne();
System.out.println("Method one in base B");
}
}
public class Base{
public static void main(String args[])
{
BaseA ba=new BaseB();
BaseB bb=new BaseB();
ba.methodOne();
bb.methodOne();
Base base=new Base();
}
public static void main(String args[][])
{
BaseA ba=new BaseA();
}
}
class BaseA
{
public BaseA(){
System.out.println("Base A constructor");
}
public void methodOne(){
System.out.println("Method one in base A");
}
}
class BaseB extends BaseA{
public BaseB(){
super();
System.out.println("Base b constructor");
}
public void methodOne(){
BaseA ba=new BaseA();
ba.methodOne();
System.out.println("Method one in base B");
}
}
public class Base{
public static void main(String args[])
{
BaseA ba=new BaseB();
BaseB bb=new BaseB();
ba.methodOne();
bb.methodOne();
Base base=new Base();
}
public static void main(String args[][])
{
BaseA ba=new BaseA();
}
}
No comments:
Post a Comment
Please post your comments. Your comments make us to write more programs for you.