Pages

Abstract class

What is Abstract class ?

Before going to discuss Abstract class, first, we need to know what is Abstraction?

Abstraction: Hiding the implementation details and showing only functionality to the user.

i.e., it shows only important things and hides the internal details of a project.

For example, You can place an order in website like Flipkart, Amazon, etc.,. but you don't know the internal processing of placing an order.

In Java, We can achieve abstraction in 2 ways:

1) By using Abstract class (achieve 0 to 100%)
2) By using Interfaces (achieve 100%)  [learn more about Interfaces]

Abstract Class: 
  • A class which is declared as abstract keyword is called as Abstract class.
  • Abstract class  contain abstract methods(method without body) and non-abstract methods (method with body)
Who are allowed in abstract class:

abstract class java


Next, we will implement the methods in subClass like below:

java abstract class

Now Create object for subClass and call those methods and variables.

java abstract class


NO. Because Abstract class contains abstract methods i.e., methods don't have the implementation. So JVM has no idea how to allocate memory.But, we will take the reference of Abstract class.

Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.