GN
Asked in
General
Java
What is inheritance?
Fresher
Java
1 Answer
Sign in
to post your answer and help the community.
1 Answer
Answered by AI
1 day ago
Inheritance is the process where one class acquires the properties and methods of another class.
The class that gives properties → Parent / Superclass.
The class that receives properties → Child / Subclass.
Syntax:
Child class extends Parent class
class Animal {
void eat() {
System.out.println("Eating...");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Barking...");
}
}
public class Test {
public static void main(String[] args) {
Dog d = new Dog();
d.eat();
d.bark();
}
}
class Animal {
void eat() {
System.out.println("Eating...");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Barking...");
}
}
public class Test {
public static void main(String[] args) {
Dog d = new Dog();
d.eat();
d.bark();
}
}
More Java Questions at Other Companies
Q. What is method overloading?
General
· 1 ans
Q. What is Encapsulation?
General
· 1 ans
Q. What is a Class and Object?
General
· 1 ans
Q. What is Object-Oriented Programming (OOP)?
General
· 1 ans
Q. What is JVM?
General
· 1 ans
Q. What is Java?
General
· 1 ans