In single level inheritance there is one base class and one child class that inherits the features of the base class. The child class inherits the child class using the keyword"extends".
Syntax for single level inheritance is:
class Child_class_name extends Base_class_name
{
void input()
{
System.out.println("Class My");
}
}
class You extends My // class You inherits My class
{
void output()
{
System.out.print("Class You");
}
}
class Slevel
{
public static void main(String arg[])
{
You obj=new You();
obj.input();
obj.output();
}
}
Syntax for single level inheritance is:
class Child_class_name extends Base_class_name
Program for Single Level Inheritance
class My //Base class{
void input()
{
System.out.println("Class My");
}
}
class You extends My // class You inherits My class
{
void output()
{
System.out.print("Class You");
}
}
class Slevel
{
public static void main(String arg[])
{
You obj=new You();
obj.input();
obj.output();
}
}
No comments:
Post a Comment