#6.9 Java Tutorial | Why do we need Abstract Class?

preview_player
Показать описание
Abstraction is a process of hiding the implementation details and showing only functionality to the user.

Need of an abstract class:-
- Java Abstract class is used to provide common method implementation to all the subclasses or to provide a default implementation.
- We can run an abstract class in java like any other class if it has a main() method.
- We create an abstract class when we don't want anyone to create an object of an abstract class.
- Instead of wasting two methods, we can only use one method which accepts all the subclass objects.

e.g.,
class Printer{
public void show(Integer i)
{
}
public void show(Double i)
{
}
}
- Here, both Integer and Double extend the Number class.
- Instead of it, we can simply use Number.
class Printer{
public void show(Number i)
{
}
}
- So, the advantage of using a Number is that it will support both Integer and Double type values.
- Number is an abstract class so we do not need to create an object for it.

In this video we will see:
- Abstraction
- Why do we need an abstract class?
- Example of an abstract class
- Number class example

More Learning :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

1. when you don't define method tou can make it abstract.
2. class need to be abstract if it has abstract method.
3. when a class extend abstract class, we must make sure
that we have define the abstract method.
4. Human(abstract class, super class), extended by
Man(concrete class, sub class)

raghavgupta
Автор

i hit like before video starts because i know it will be always best..you are awesome sir

rineeshch
Автор

Easy to understand. Very important for big projects. Thank you. Keep on...

vladanulardzic
Автор

a better question is: why to use abstract class and not interface?

anakin
Автор

Thank You Sir for this awesome and genuine content.
This q looked difficult to me before but now its a piece of cake for me.
All thanks to you Sir, May GBU with lots of love long life success happiness and enjoyment
Thanks a lot again

TeachingCodes
Автор

But this can be done by making writer, an interface as well. So when should we use abstract class instead of interface after java 8...?

NitinKumar-opkl
Автор

In the example that you've given, why use abstract class, you can use interface instead

sriramgopalakrishnan
Автор

Sir.., then what is the difference between overriding and abstract methods except partial implementation????

nishanthmurugan
Автор

I am not understanding why it has so many less views despite it being crisp and complete.

jagadeeshgurana
Автор

but you created the object of it so how to use it?
Number i;
Integer i;

why it does not show an error message?

bakhtatal
Автор

You had told we cannot create object of number as it being abstract, so how are you passing number? Can you please explain bit more

harisiri
Автор

What was that horrifying screaming at 2:24

aonegamer
Автор

An abstract class is like prototype is it right ...?

vamsireddy
Автор

You are great sir ! Please more videos I’m now to java Programing!

h.rehaief
Автор

very nice to learn everything sir tq u alot

viswanathan
Автор

we can use genric also then why abstract

prashantpandey
Автор

this is wrong explanation. Abstract class are those which are template kind of things which we cant create object .For example the Animal is the one which dont have object as real . Thats why Animal is abstract class. And the common actions of animal will be created in abstract class.

ashokbantu
Автор

I could not open Integer class or Number class from eclipse as shown in video. Can any one please tell how to do it?

vinayakdasari
Автор

Please make video on Web services in java

kamalajavaworld
Автор

Hi, sir I want your help, when you click on integer you can view its source file(i.e. Integer.class), but while I am clicking on integer in my pc, I am not able to do so, and it is asking for add source file instead,

prashantsingh