filmov
tv
JAVA : What is inheritance in Java? SDET Automation Testing Interview Questions & Answers

Показать описание
Level up your SDET and QA skills! 🚀 JAVA : What is inheritance in Java?
SDET Automation Testing Interview Questions & Answers
We will be covering a wide range of topics including QA manual testing, automation testing, Selenium, Java, Jenkins, Cucumber, Maven, and various testing frameworks.
JAVA : What is inheritance in Java?
Inheritance is a mechanism in Java that allows you to create a new class based on an existing class.
The new class, known as the subclass, inherits the properties and methods of the existing class, known as the superclass.
The subclass can also add new properties and methods or override the properties and methods of the superclass.
Here's an example:
class Animal {
public void makeSound() {
}
}
class Dog extends Animal {
public void makeSound() {
}
}
Animal animal = new Animal();
Dog dog = new Dog();
In this example, we've created a superclass called Animal with a method called makeSound().
We've then created a subclass called Dog that extends Animal and overrides the makeSound() method.
We've created objects of both classes and called the makeSound() method on each object, demonstrating how the subclass can override the behavior of the superclass.
Комментарии