Thursday, September 26, 2019

Questions on Aggregation in Java

Questions on Abstract Classes in Java


1) Abstract class must have only abstract methods. True or false?
False. Abstract methods can also have concrete methods.
2) Is it compulsory for a class which is declared as abstract to have at least one abstract method?
Not necessarily. An abstract class may or may not have abstract methods.
3) Can we use “abstract” keyword with the constructor, Instance Initialization Block, and Static Initialization Block?
No. Constructor, Static Initialization Block, Instance Initialization Block, and variables can not be abstract.
4) Why final and abstract can not be used at a time?
Because final and abstract are totally opposite in nature. A final class or method can not be modified further where as abstract class or method must be modified further. 
“final” keyword is used to denote that a class or method does not need further improvements. 
“abstract” keyword is used to denote that a class or method needs further improvements.
5) Can we instantiate a class which does not have even a single abstract method but declared as abstract?
No,
 We can’t instantiate a class once it is declared as abstract even though it does not have abstract methods.
6) Can we declare abstract methods as private? Justify your answer?
No. Abstract methods can not be private. If abstract methods are allowed to be private, then they will not be inherited to sub class and will not get enhanced.


No comments:

Post a Comment

Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > <...

Followers

Search This Blog

Popular Posts