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

Can we store variables in local blocks?

0 Answers   Global Logic,


Explain public static void main(string args[]) in java.

0 Answers  


If I only change the return type, does the method become overloaded?

0 Answers  


if two references are having same hash codes,is that means those are refering to same object?

5 Answers   CTS,


What is application system?

0 Answers  






What are the two types of java programming?

0 Answers  


What collections you have worked on? Internal working of Hashmap?

1 Answers   Bravura Solutions,


Map map = new HashMap(2); map.add(“1”,”one”); map.add(“2”,”two”); map.add(“3”,”three”); What will happen at this line?

5 Answers   Rolta,


what is struts-config-xml?and its use?

3 Answers  


what is use of functional interface in java 8?

0 Answers  


Explain the difference between a Thread and a Process.

0 Answers   Ciena,


What is finally in Java?

0 Answers  


Categories