Computer Science, asked by cutiee65, 1 year ago

give one good example of inheritance in blue j

Answers

Answered by siddhartharao77
4

Short notes on Inheritance:

(i) Inheritance is a process in which "one class acquires the property of another class".

(ii) It defines is-a relationship between super class and its subclass.

(iii) Following are the types of Inheritance:

(a) Single Inheritance

(b) Multilevel Inheritance

(c) Hierarchical Inheritance

Sample Examples:

(i)

class Brainly

{

void display()

{

System.out.println("Main");

}

}

class Derived extends Brainly

{

void show()

{

System.out.println("Child");

}

public static void main(String args[])

{

Derived d  = new Derived();

d.display();

d.show();

}

}

Output:

Main Method

Child Method

(ii)

class Brainly

{

int a = 10000;

}

class Quora extends Brainly

{

int b = 20000;

public static void main(String args[])

{

Quora q = new Quora();

System.out.println(q.a);

System.out.println(q.b);

}

}

Output:

10000

20000

Hope it helps!


siddhartharao77: :-)
Answered by Siddharta7
3

Java inheritance refers to the ability in Java for one class to inherit from another class. In Java this is also called extending a class. One class can extend another class and thereby inherit from that class.

When one class inherits from another class in Java, the two classes take on certain roles. The class that extends (inherits from another class) is the subclass and the class that is being extended (the class being inherited from) is the superclass . In other words, the subclass extends the superclass. Or, the subclass inherits from the superclass.

Another commonly used term for inheritance is specialization and generalization. A subclass is a specialization of a superclass, and a superclass is a generalization of one or more subclasse

Similar questions