Inheritance concept is encouraged in java as it is an OOP language.
class B : Inherits A
class Main : In which main() is written.
class Aclass A : Internally inherits java.lang.Object
{
public void printA()
{
System.out.println("I am in class A");
}
}
class B extends A
{
public void printB()
{
System.out.println("I am in class B");
}
}
class Main
{
public static void main(String args[])
{
A a=new A();
a.printA();
// a.printB(); error
B b=new B();
b.printA();
b.printB();
}
}
class B : Inherits A
class Main : In which main() is written.
No comments:
Post a Comment