Professional Documents
Culture Documents
In the Java language, classes can be derived from other classes, thereby
inheriting fields and methods from those classes. Inheritance means
establishing a logical relationship between two classes. In other words,
inheritance means extending class functionalities (code reusing). Here,
Relationship is categorized into two types:
Is-a relationship
Has-a relationship
What is Inheritance in Java
Single Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Note: Compared to C++, Java does not support multiple inheritances
directly. Individually, multiple inheritances are supported in Java using the
interface concept.
class one
{
public void print_hello()
{
System.out.println("Hello");
}
}
// Drived class
public class HierarchicalInheritance
{
public static void main(String[] args)
{
three g = new three();
g.print_hello();
two t = new two();
t.print_world();
g.print_hello();
}
}
Output:
Hello
World
Hello