How does abstract modifier work?



How does abstract modifier work?..

Answer / javamasque

Abstract means no concrete, it isn’t directly used. It depends on an implementation to be used. The abstract key word can be used before class (top-level/inner) or method.

Abstract class
• If we make a class abstract, it is not directly instantiated. It have to have a child class to be used.
• It is only be used through inheritance.
• The legacy or common functionality are kept in abstract class.
• It is also used for up casting and dynamic polymorphism.
• It is mostly used in factory design pattern.
• An abstract class can implement and extends another interface and class.

Abstract method
• An abstract doesn’t have any body.
• It has to have an override non-abstract method.
• If a class has an abstract method, then the class has to be abstract.
• An abstract method can only be set visibility modifier either public or protected.

Abstract inner class
• An inner class can be abstract but it is not commonly used and is not recommended also.
• A tight coupling utility is implemented as inner class but if the utility is too complex and we need to segregate into different inner subclasses, then we should go for abstract inner class. The scenario is very rare and it may not come in web applications but may come very big swing application.

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More Core Java Interview Questions

class A{ some variables; public void a()throws Excepion1,Exception2{....} } class B extends A{ variables... public void a()throws E2,E3{.....} } Qns: here override of methods occurs or not,ore else wil give any compilation error or run properly..plz tell me briefly whts happening with the above codes....

4 Answers   Quinnox,


What is onClassLoader in java?

5 Answers   Cap Gemini,


What are annotations in java?

0 Answers   Impetus,


please tell me what is wrapper class in java with example ?

6 Answers   HP,


Can a constructor be private and how are this() and super() method used with constructor?

0 Answers   Flextronics, Hexaware,






there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box.

0 Answers   Manhattan,


What is the difference between Integer and int?

10 Answers   Infosys,


What is the output of the below java program?

0 Answers  


What do you mean by stream pipelining in java 8?

0 Answers  


What is bean? Where it can be used?

0 Answers  


Difference between notify() method and notifyall() method in java?

0 Answers  


How we create object in copy constructor?

0 Answers   HCL,


Categories