How does abstract modifier work?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What are recursive functions? Give some examples?

619


Can we overload the main() method?

551


What is the use of set in java?

612


What are operators and its types?

575


What will be the initial value of an object reference which is defined as an instance variable?

641






what is the constructor and how many types of constructors are used in java?

538


Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.

1610


What does the ‘static’ keyword mean? Is it possible to override private or static method in java?

567


What are thread local variables?

555


What are different types of references?

534


What is foreach loop in java?

536


What are thread safe functions?

514


How to set the permissions to a file in java?

542


How many ways can we create singleton class?

506


Name few java 8 annotations ?

566