Saturday, July 1, 2023

What is Abstract Class and Method in Java? Examples and Frequently asked Questions

Both abstract class and abstract methods are very important concepts in core Java and every Java developer should have good understanding of what they are, when to use them and how to use them. They are also very popular on core Java job interviews as well as on Oracle Java certifications e.g. OCAJP or OCPJP.  You will often find a lot of code based questions testing essential core Java concepts based upon abstract class and methods in the real exam. All good mock exam simulators e.g. Whizlabs and Certification-questions also contains a lot of questions testing and explaining these key concepts, which shows how important they are for Java developers. 

Wednesday, May 10, 2023

Is it possible to have an abstract method in a final class? Example

This is one of the interesting core Java questions which was asked to one of my readers recently during a telephonic interview for a Java developer job interview. Even though he knows that you cannot make an abstract class final in Java, he got confused by the wording of the methods. The answer is simple, No, it's not possible to have an abstract method in a final class in Java. Why? because as soon as you declare an abstract method in a Java class, the class automatically becomes an abstract class and you cannot make an abstract class final in Java as discussed before, hence it's not possible to have an abstract method in a final class in Java.

Saturday, April 15, 2023

Can you declare Abstract Class or Method Final in Java? If not, why?

If you are wondering whether you can use both abstract and final modifier together with a class or method in Java then you are not alone. This is one of the frequently asked, theory based Java questions which is sometime tricky to answer, particularly if you don't have complete knowledge of Java fundamentals. The answer of this question is No, you can not declare abstract class or method final in Java because both abstract and final keywords are mutual exclusive. Anything which is abstract cannot be final and vice-versa. It's like a person cannot be living and dead at the same time.