Single Inheritance Example

When a class inherits another class, it is known as a single inheritance. In the example given below, Dog class inherits the Animal class, so there is the single inheritance.

File: TestInheritance.java


\begin{lstlisting}
class Animal{
void eat(){System.out.println(''eating...'');...
...tring args[]){
Dog d=new Dog();
d.bark();
d.eat();
}
}
\end{lstlisting}

Output:


\begin{lstlisting}
barking...
eating...
\end{lstlisting}