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

Which method must be implemented by all threads?

717


What is the abstract class?

594


Is 0 a prime number?

568


what is meant by Byte code concept in Java?

595


Write a java program that prints all the values given at command-line.

546






What is use of functional interface in java 8? Explain

562


Write a program to print all permutations of string?

673


How do generics work in java?

517


What is the difference between an array and an array list?

498


What happens if we don’t override run method ?

560


When throw keyword is used?

582


What should I import for arraylist in java?

506


What about method local inner classes or local inner classes in java?

547


Is null function in java?

562


Can we declare a class as abstract without having any abstract method?

548