Java – Single Inheritance

Note: We always instantiate (create object) of Child in Inheritance

Single Inheritance: Accessing the functionality of Parent(single level)

class Employee
{
            void doWork()
            {
                        System.out.println(“Employee do work”);
            }
}
class Manager extends Employee
{
            void monitorWork()
            {
                        System.out.println(“Manage do work as well as monitor others work”);
            }
}
class Company
{
            public static void main(String[] args)
            {
                        Manager m = new Manager();
                        m.doWork();
                        m.monitorWork();
            }
}
In Object creation, Parent object creates first then properties inherit to Child.
We can check this creation process by defining constructors in Parent and Child.
class Parent
{
            Parent()
            {
                        System.out.println(“Parent object created”);
            }
}
class Child extends Parent
{
            Child()
            {
                        System.out.println(“Child object created”);
            }
}
class Inheritance
{
            public static void main(String[] args)
            {
                        Child obj = new Child();
            }
}
Scroll to Top