Hello Friends, In this Blog Post I am going to let you know about a few more interview questions of core java related to Abstract Classes and Interfaces.
Core java interview questions covers all the important questions of the topics mentioned above.
These core java interview questions is a great help to remember all the important highlights and important topics from each java chapter.
These interview questions will surely help to understand a few very confusing concepts in java.
How can you force your programmers to implement only the features of your class?
We can do it by writing an abstract class or an interface.
Can you declare a class as abstract and final also?
No, an abstract class needs subclasses. the final keyword represents subclasses which can not be created. So, both are quite contradictory and can not be used for the same class.
What is an interface?
An interface is a specification of method prototypes. All the methods of the interface are public and abstract.
Why the methods of an interface are public and abstract by default?
The interface method is public since it should available to third party vendors to provide the implementation. They are abstract because their implementation is left for third party vendors.
Can you implement one interface from another?
No, we can not be implementing an interface that means writing the body for the methods. this can not be done again in an interface since none of the methods of the interface can have a body.
Can you write a class within an interface?
Yes, it is possible to write a class within an interface.
What is callback?
The mechanism of calling a function from another function bypassing its memory address is known as ‘callback’ callbacks are achieved in java with the help of interface references.
What is the difference between abstract class and an interface?
The difference between abstract class and interface is given below.
An abstract class is written when there are some common features shared by all the objects.
An interface is written when all the features are implemented differently in different objects.
When an abstract class is written, it is the duty of the programmer to provide the subclasses with it.
An interface is written when the programmer wants to leave the implementation to the third-party vendors.
An abstract class contains some abstract methods and also some concrete methods.
An interface contains only abstract methods.
An abstract class can contain instance variables also.
An interface can not contain instance variables, it contains only constants.
All the abstract methods of the abstract class should be implemented in its subclasses.
All the (abstract) methods of the interface should be implemented in its implementation classes.
An abstract class is declared by using the keyword abstract.
The interface is declared using the keyword interface.
So this was all about the Core java interview questions in this topic.
These Core java interview questions could be a great help in your college viva, academic study, and any job interview.
In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.
Hope! you would have enjoyed this post about Core Java Interview Questions Part 13/Abstract Classes and Interfaces.
Please feel free to give your important feedbacks in the comment section below.
Have a great time!