Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Abstraction Placement Questions and Answer - Vaibhav A Sharam

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

VAIBHAV ANAND SHARMA JAVA BY

KIRAN VAIBHAV ANAND SHARMA By


VAIBHAV ANAND SHARMA

VAIBHAV ANAND SHARMA JAVA BY


wertyuiopasdfghjklzxcvbnmqwertyuio
pasdfghjklzxcvbnmqwertyuiopasdfghj
klzxcvbnmqwertyuiopasdfghjklzxcvbn
PLACEMENT QUESTIONS ANSWERS
JAVA BY KIRAN
mqwertyuiopasdfghjklzxcvbnmqwerty CORE JAVA

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)

Placement Questions and answer

“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.

Q.2 How to achieve abstraction in java ?

Ans Abstraction can be achieved in two ways :

1. By using Interface we can achieve fully abstraction


2. By using Abstract class we can achieve partial abstraction.

Q.3 What are the types of abstraction ?

Ans There are two type of abstraction we can use :

1. Fully abstraction : Interface


2. Partial abstraction : Abstract class

Q.4 Can u explain interface ?

Ans. Features of the interface are given below :

1. It looks like same as class.


2. It doesn’t have any constructor , so we cannot create object of it.
3. In order to use interface we have to implement it in our class.
4. All variables of interface are public static final.
5. All methods of interface are public abstract means methods don’t have any body to
write logic inside it.
6. If we implement interface in our class then all method must be override.
7. With the help of interface we can achieve multiple inheritance.

Created by – Vaibhav Anand Sharma, Java by kiran


3|Placement question’s solution (Java By Kiran)

Q.5 Why we cannot extend interface in our class?

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.

Q.6 Why multiple inheritance is possible using interface ?

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.

Q.7 Why we cannot implement and interface in another interface ?

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.

Q.8 Can u explain abstract class ?

Ans. Features of the abstract class are given below :

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.

Created by – Vaibhav Anand Sharma, Java by kiran


4|Placement question’s solution (Java By Kiran)

Q.9 Explain types of interface ?

Ans. There are mainly two types of interfaces

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 :

1. Runnable interface : it contains only one run() method, used in multithreading.


2. ActionListener : it contains only actionPerformed() method.
3. itemListener : it contains only itemStateChanged() method.

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 :

1. Serializable : From java.io.package. It used for the process of serialization.

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.

All these three are the built in marker interface of java.

Q.10 What is Factory design pattern ?

Ans. When abstract class is used as a mediator between interface and class, then this is
called the Factory designed pattern.

Q.11 What is Agile methodology ?

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.

Created by – Vaibhav Anand Sharma, Java by kiran


5|Placement question’s solution (Java By Kiran)

Created by – Vaibhav Anand Sharma, Java by kiran

You might also like