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

preview_player
Показать описание

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.
Рекомендации по теме
Комментарии
Автор

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() {
System.out.println("The animal makes a sound.");
}
}

class Dog extends Animal {
public void makeSound() {
System.out.println("The dog barks.");
}
}

Animal animal = new Animal();
animal.makeSound(); // Output: The animal makes a sound.

Dog dog = new Dog();
dog.makeSound(); // Output: The dog barks.

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.

sdet_automation_testing
welcome to shbcf.ru