The property of data abstraction is that only the most important details are displayed to the user. The user needs to be shown the units that are trivial or non-essential. For example, a car is considered a whole rather than its distinct parts.
The process of identifying only the required characteristics of an object while ignoring the irrelevant details is known as data abstraction. The features and behaviours of an object assist in distinguishing it from other things of the same sort and classifying and grouping them.
Consider the case of a man behind the wheel of a car. The man only knows that pressing the accelerator will increase the speed of a car or that applying the brakes will stop it, but he has no idea how pressing the accelerator will increase the car's speed. He also needs to learn about the car's inner mechanism and how the car's accelerator, brakes, and other controls are implemented. This is the definition of abstraction.
In Java, abstraction is performed using interfaces and abstract classes. We can accomplish 100 per cent abstraction via interfaces.
Abstract classes and abstract methods:
An abstract class has the abstract keyword in its name.
The term "abstract method" refers to a declared but not implemented method.
An abstract class may or may not have all the abstract methods. Some of these could be concrete procedures.
A specified abstract method must always be redefined in the subclass, forcing overriding OR making the subclass abstract. Every class with one or more abstract methods must also include the abstract keyword in its declaration.
An abstract class can't have any objects.
An abstract class can not be directly instantiated with the new operator.
The default function object [[native code]] is always present in an abstract class and can contain parameterized constructors.
An example of when to utilize abstract classes and abstract methods
There are scenarios in which we will wish to construct a superclass that declares the structure of a particular abstraction without providing a complete implementation of every method. There will be occasions when we wish to construct a superclass that defines a generalization from which all of its subclasses will use it, leaving each subclass to fill in the details.
Consider the famous "shape" example, which may be used for a computer-aided design system or a gaming simulation. The base type is "shape," and each form has a colour, size, and so on. Specific shapes, like circles, squares, triangles, and so on, are derived (inherited) from this, each of which may have different properties and behaviours. Specific shapes, for example, can be flipped. For example, when you wish to determine the area of a shape, some behaviours may be different. The shapes' similarities and distinctions are embodied in the type hierarchy.
Summary:
The process of identifying only the required characteristics of an object while ignoring the irrelevant details is known as data abstraction. In Java, abstraction is done using interfaces and abstract classes. The term "abstract method" refers to a declared but not implemented method. An abstract class can't have any objects. A method specified as abstract must constantly be redefined in the subclass.
Default function Object() { [native code] } is always present in an abstract class. An example of when to utilize abstract classes and abstract methods is given.
0 Comments