Abstraction Placement Questions and Answer - Vaibhav A Sharam
Abstraction Placement Questions and Answer - Vaibhav A Sharam
Abstraction Placement Questions and Answer - Vaibhav A Sharam
uiopasdfghjklzxcvbnmqwertyuiopasdf
WRITTEN BY – VAIBHAV ANAND SHARMA
ghjklzxcvbnmqwertyuiopasdfghjklzxc
Vaibhav Anand Sharam Java By Kiran
JAVA BY KIRAN VAIBHAV ANAND By
SHARAMA JAVA BY JAVA BY KIRAN
JAVA BY KIRAN JAVA BY KIRAN JAVA
BY KIRAN JAVA BY KIRAN JAVA BY
KIRAN JAVA BY JAVA BY KIRAN Java
KIRANKIRAN JAVA BY KIRAN BY Java
2|Placement question’s solution (Java By Kiran)
“ABSTRACTION”
Q.1 What is abstractionin java ?
Ans Exposing only required things to the user is called as abstraction. Or we can say hiding
certain details or showing only required things. For example a car is viewed as a car rather
than its essential components which is having its inside and which is crucial for its working.
Like streaming apps which allow only to subscribers to show specific data.
Ans It is because in sub class, when we write constructor it has super(); call by default which
calls the super class constructor where constructor is not available.
Ans. It is because interface has abstract methods which don’t have body, it will create
ambiguity suppose we have two class which have same method signature so if we extends
both class then java will get confuse that whom to call, but in interface methods are abstract so
we can implement any number of interfaces in our class and override methods and can write
any valid code inside it.
Ans. An interface can extend any number of interfaces but one interface cannot implement
another interface it is because if any interface is implemented then its method must be defined
and interface never has the definition of any method. Because implements keyword is used to
implement unimplemented methods .
In simple way we can say if we implements interface1 in other interface2 then the methods of
interface1 must be implemented (Defined) in the interface2 ,which is not possible for interface,
as we do after implementing in class , because in interface methods are abstract means they
have no body, so we cannot implement interface in interface. So we will extend it so the
methods of interface1 will inherit in interface2 now we can implement interface2 in any class
for implementation of interface1’s features.
1. Abstract class has constructor but we cannot create object of it because abstract
methods don’t have body.
2. If a single method is abstract then my class must be an abstract class.
3. If my class is abstract then there is no compulsion to add abstract method.
4. Abstract class can be extended.
5. Abstract class can be used as intermediate function between interface and Class to
build applications as factory design pattern.
1. Functional interface
2. Marker interface
Functional interface : It has only one pure abstract method. It can have any number of default
and static methods but only can contain only one abstract method. Functional interfaces
introduced as a part of JAVA 8.
Example of functional interface :
Marker interface : An interface that does not contain any method, filed, Abstract method and
constants called marker interface. Also , if an interface is empty then it is called marker
interface. This interfaces are used to apply some set of rules.
Example of marker interface :
2. Cloneable : From java.lang.package. It used to make the copy of object , after data
transfer from one location to another location at the time of serialization.
3. Remote : From java.rmi package. It marks an object as a remote that can be access by
the host of another machine.
Ans. When abstract class is used as a mediator between interface and class, then this is
called the Factory designed pattern.
Ans. It is a time bound iterative approach to software or web application delivery that builds
products incrementally from the start of the project, instead of trying to deliver all at once.
Means by adding features we submit it to client step by step so that he can use this and can
notify to their customer for the upcoming features.