Java4teachus

Thursday, July 04, 2019

Single Inheritance In Java

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


single-Inheritance-in-Java.jpeg
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
Alpha-beta-program-In-java,jpeg

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:-
Single-Inheritanc-Program-In-Java.jpeg

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Thanks alot...
      Thanks for visiting my site ...

      Delete
  2. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.Surya Informatics

    ReplyDelete

Thanks for visiting my site..