Lab 8 Sarmad
Lab 8 Sarmad
Lab Objectives:
1. Understanding the concept of inheritance
2. Implementation of Inheritance in java
Software Required:
Netbeans IDE
Inheritance in Java
void showij() {
System.out.println("i and j: " + i + " " + j);
}
}
// Create a subclass by extending class A.
class B extends A
{ int k; void
showk() {
System.out.println();
System.out.println();
System.out.println("Sum of i, j and k in subOb:"); subOb.sum();
}
}
TASK 2: Create a class A which has two data members one is public and other
is private. Create another class B which extends class A. Try to display values of
both data members of class A in class B.(take protacted AS)
public class A {
class B extends A {
B sc =new B();
System.out.println(sc.name);
System.out.println(sc.id);
System.out.println(sc.Adress);
} }
import java.util.Scanner;
public class Employe {
}
class Regular_Employee extends Employe{
Please Fill the blank space with respective answers to following questions:
Question 1: What are different types of inheritance?
Single-level inheritance.
Multi-level Inheritance.
Hierarchical Inheritance.
Multiple Inheritance.
Hybrid Inheritance.
If we inherit a class from another class and create an object of the derived class, it is clear
that the default constructor of the derived class will be invoked but before that the default
constructor of all of the base classes will be invoke, i.e the order of invocation is that the
base class's default constructor .
THE END