Inheritance Interface Java (1)
Inheritance Interface Java (1)
Inheritance
Inheritance is a mechanism wherein a new class is derived from an existing class. Types:
- Single Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
The 'final' keyword prevents further inheritance. A final class cannot be extended, and a final method
cannot be overridden.
class A {
class B extends A {
class C extends B {
class Book {
int stock;
void display() {
System.out.println(title + " by " + author + ", Rs." + price + ", Stock: " + stock);
class Demo {
Demo() { }
Demo(int x) { System.out.println(x); }