Skip to main content

Posts

Showing posts with the label oop

Object-Oriented Programming in Java — Abstraction

To reduce complexity, abstraction in Object-Oriented Programming refers to showing only the essential features of an object to the user and hiding the inner details. In other words, the user only needs to know “what an object does?” rather than “how it does?” Example Image by Author The above sketch is a good real-world example of abstraction. A user can only use and connect with the application’s limited functionality and is uninformed of the system architecture or how the application was built up. Typically, users are only involved with an application’s functionality. Nothing at all is hidden from an administrator , who has access to many more features of the application. The administrator can monitor user activity, understand how the application was created, and implement new features by implementing them in the system. In the previous example, the abstraction is implemented to the user but not to the administrator . Image by Author Let’s take a look at another example of abstract...

Object-Oriented Programming in Java — Multiple Inheritance

Multiple Inheritance occurs when a class is derived from more than one base class, i.e. when a class has more than one immediate parent class. For example 1. A Hyundai Elantra IS A Car 2. A Hyundai Elantra IS A Sedan as well A class in Java cannot extend from more than one class. As a result, the question of “ how can we implement multiple inheritances ” arises. Interfaces are the answer to the preceding question. Interfaces can be used to implement multiple inheritances in Java. A class may implement multiple interfaces, and an interface may extend from multiple interfaces. Take the same example mentioned above. That can be implemented using the following. 1. A base class named Car 2. An interface named IsSedan 3. An Elantra class derived from Car and implementing IsSedan The above illustration then becomes, Image by Author Implementation in Java The output is The model of Elantra is: 2019 The manufacturer of Elantra is: Hyundai The variant of Elantra is: Sport The bootspac...