filmov
tv
#6.9 Java Tutorial | Why do we need Abstract Class?
Показать описание
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
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
Комментарии