What is Abstract Class and Interface in Java?

What is Abstract Class and Interface in Java?

By - SevenMentor12/23/2025

This dedicated article of Java Classes In Pune Trainer will be a short one with few words on the interfaces and abstract classes in java. There is a lot of mist in using these two things, but as I always mention to people that Encapsulation is one of the most powerful feature in java and the golden rule of Java (Don't forget) Everything has its own purpose. Therefore, if there are two such features (abstract class and interface) in the language, they must have different motivations too.

 

Point of the Article

The article explains in detail with Abstract Classes And Interfaces, that is "what is the difference between interfaces and abstract classes as a design issue?" and also how good API should distinguish between both of them. What should you be thinking about while you are writing an API? When You will use ‘interface’ and when you will user ‘abstract class.

Have patience and read till last, if you are looking for an answer with which you can give in interviews and impress the interviewers. Before we write about the differences between these in this article, Let us hear something on abstraction. Now I want you to get a quick look at an image below and give me a few seconds of thought about question below: Can each of this object in the image belong to various different categories?? What If I tell you that Find out to which category the objects belong if I have to classify them). Few of them are enlisted –

Vehicles

Airplane

Tank

Bike

Truck

Bicycle

Boat

Car

Flyable

Kite

Bird

Airplane

We can have as many categories of outcomes as we want to but for the purpose of this discussion, let's simplify down to two. So what, exactly did we observe and classify? How does it classify?. I mean behaviors and I own the other side of that, capabilities. The categorization is palimony.

second is more complex feature-based behaviour. So now when we know how to categories things, let me explain you the word ‘Abstraction’.” We should realize what is between feature, capability and behavior. Capability is wha.t an entity ( a thing, a how/what system ) can do. Behavior is how an object behaves feature is the characteristic of an object.

There's a kind of a taste and we can sense that, the entities in the first class just fit together more naturally; they're sort of inseparable or closely attached to one another. While the members of the second class are more nearly group and do not always need to be closely situated.

In Java, and other Object oriented programming language has the concept of abstraction which allows you to separate the implementation from an interface and it is one of the five fundamentals ( we will later see) along with Inheritance, Polymorphism Encapsulation Class and Object.

Abstraction in Java can be achieved through Interface and Abstract class in Java. Interface or an abstract class is something which java can say it is not concrete,something that is not complete.

if you wish to go with interface or abstract class, all you have to do is extend and implement an abstract method with its concrete behavior.

One form of Abstraction is, for example an interface that again does not say anything when used about how that behaviour a method. for example - you make an interface which we call Server and inside it have start() and stops () methods. You can name it as an abstraction of Server class since individual server might have different way to start and stop and so on.

Abstraction in Java is achieved through abstract class and interface. What is abstraction in java actually?, How to achieve it? what is difference between Abstract class and Interface in Java is one of the most popular core java interview question because abstract class and interface is a very important concept, which has been covered by almost all major Java interviews.

One among the concept which is difficult to master even for few ciscoians would be Abstraction. This is what the typical source code looks like; and if you combine two levels of abstractions then it can introduce in-flexible code so use discretion.

Explore Other Demanding Courses

No courses available for the selected domain.

Abstraction

In Object-Oriented Concept Abstraction is”Exposing functionality and Hiding Implementation details”. That's what we tell when we say a behavior and a feature of an object kind that is still invisible. Abstraction is a programming concept the means of abstracting the characteristics/behavior of an entity (type) and representing it as a group. Let me attempt to simplify it: Suppose we are doing an application to coordinate vehicles. Now let´s name what vehicles we can have, cars, trucks, motorcycles and bikes, aircrafts, boats. Further more if we look at the there are none of them, which is a physical object that I would want like to indicate I need to tell when say for example if I were ever make statements about cars right? - so whenever you can be sure and ask me what do i own in real life And anyone could send to me. I would say closer to, I have a Car (C) which is Brand Honda, red in color registration number XYZ1234 and so on...Basically something unique that can be identified as being the car C. So the car (C) is an instance of Vehicle class. And, we will also have many concrete examples for each of the class of vehicles. Where does abstraction fit in? Like I also said above, I believe one should abstract to represent a feature or behavior :) Now if you observe it closely then now from this example of yours, all the vehicles will have few properties in common like they can have a color, an engine number, max speed and many more. Ways of using Abstraction We use Abstraction with the help of following language features:- Abstract class:So, what if I ask you to construct an Object for a Car, and assume each one them will write classes/ source code,there is a possibility that we miss few of those essential feature. Also I want to force my API( Application programming interface) user to also specify these common characteristics for all the vehicles. This is because of the Familiar and common set of facilities in all cars, this is why you have an abstract class. We can abstract out the common function into another class as well Its a good practice to keep a separate class for those features which we cannot logically create an object of it. For instance if we create Object a Vehicle it does not seem too wise. However if we have Object of a Car class it make sense. Thus, when writing an API we wish to use abstract classes for internal use (of the API).

 

Interfaces

The first part/utterance that gets produced is one of L1 or L2 and interfaces are only applied in the second part/categorization, when a capability X has been generated. So interfaces definitely can have a close relationship between objects which implement them. We can argue, but we have some kind of loose coupling when you’re talking about interfaces. I'd tend to hold that, for all the same reasons that we've banned lateral cabal; not everybody writing code is a Python programmer. Or if they are, then I'll generally say that it can probably be done via an interface or whatever else provides the relevant method signature.

 

The Big Debate

Both the class Interface and Abstract both can give some behavior to any eventual implementing or extending from then why we should not always use a interface as it provides more extension area to the implementing class to extends another calss.

The reply may be a bit lengthy. When it comes to providing functionality, both interfaces and abstract classes serves same purpose but when we talk about providing properties or attributes to the children, lets call them features then abstract classes will outperform interface because anything that extends an abstract class can have as protected member variables of parent class also.

If we are looking to expose an API to the users (other applications, classes etc.) then in that case firstly we need some strong reason of using interface as Interface is a contract which means if any class implements an interface it will fulfill the contract i.e. implement all methods inside the interface. For example: If there is someone who wants to take a contract of Flightable interface, then All have to give the implementation for fly method and they should write down HOW should the implementing class ‘fly’.

Also explore our YouTube Channel: SevenMentor

Get Free Consultation

Loading...

Call the Trainer and Book your free demo Class..... Call now!!!

| SevenMentor Pvt Ltd.

© Copyright 2025 | SevenMentor Pvt Ltd.

Share on FacebookShare on TwitterVisit InstagramShare on LinkedIn