Single Inheritance In Java
Definition
If any class is deriving from the another class, it can be called as single inheritance. In this inheritance these exists single base class and single derived class.
Example
➧ In the above example, when we defined the java program on inheritance concept first we can create Base class (parent class) and later create derived class(child class).
➧ In oops concepts we can use and calls the one class features into another class by using inheritance which is shown below syntax.
Syntax
class A
{
---------
---------
}
class B extends A
{
--------
--------
}
➧ Note:- whenever we call the based class features into derived class then we must defined the keyword called as extends Other wise compile time error.
Q. Write a java program which will illustrate the concepts of single inheritance.
Program
class Alpha
{
void show()
{
System.out.println("Hellow Alpha");
}
}
class Beta extends Alpha
{
void show1()
{
System.out.println("Hellow Beta");
}
}
class Test
{
public static void main(String[] args)
{
Beta b=new Beta();
b.show();
b.show1();
}
}
Output
{
void show()
{
System.out.println("Hellow Alpha");
}
}
class Beta extends Alpha
{
void show1()
{
System.out.println("Hellow Beta");
}
}
class Test
{
public static void main(String[] args)
{
Beta b=new Beta();
b.show();
b.show1();
}
}
Output
Program: 2
class School
{
void schoolInfo()
{
System.out.println("Brilliant School From Dhatmavaram");
}
}
class Inter extends School
{
void interClgInfo()
{
System.out.println("Sri Sai Krupa Jr College From Dhatmavaram");
}
}
class SingleInheritance
{
public static void main(String[] args)
{
System.out.println("---------------");
Inter i=new Inter();
i.schoolInfo();
i.interClgInfo();
System.out.println("---------------");
}
}
OutPut:-
This comment has been removed by the author.
ReplyDeleteThanks alot...
DeleteThanks for visiting my site ...
Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.Surya Informatics
ReplyDelete