Moreover, the constructor of the latter must call the constructor of the corresponding superclass. When to use abstract classes For example, if you need to create and define a common interface and behavior that will be used by several classes at the same time. Let's look at a specific example. Let's say you are creating a game that involves a variety of geometric shapes: circles, squares, triangles.
Rules and restrictions when working Albania Email List with abstract methods It's worth knowing that there are several rules that limit working with abstract methods in Java: an abstract method cannot be declared final or private; it must be declared inside an abstract class; a concrete subclass that extends an abstract class must provide implementations for all of its inherited abstract methods. We are offering a 60% discount on until February 25 In just 9 months you can get a job with an income of 150,000 rubles Book a discount Abstract methods and abstract classes are often used together - this makes it possible to create a common interface for a group of related classes.

Let's continue to explore this with our shape game and see how we can use abstract methods to define a general interface that calculates the perimeter and area of shapes. So, we already have an abstract class Shape, which contains abstract methods for determining the parameters of the shapes we need: public abstract class Shape { protected int x, y; public Shape