Let's learn java programming language with easy steps

Tuesday, 26 September 2017

Interview Questions on Abstraction in Java

Java Abstraction Interview Questions

Abstraction Interview Questions in java

Now, Here we are going to discuss the most important core java interview questions and answers which is "interview questions on abstraction in java".

So let's start with abstraction interview questions.


(1) What is abstraction in java?

In java, Abstraction means show functionality and hide complexity or internal details or hide implementation details to the user is know as abstraction in java.

For example:

The best example in the world of abstraction is ATM machine where we can withdraw or transfer money easily but how it happens? we don't know. We don't know internal details or implementation details.


(2) How to achieve abstraction in java?

There are two ways in java we can achieve abstraction.
  • By using abstract class(0 to 100%).
  • By using interface(100%).


(3) What is abstract class in java?

When we declared any class with "abstract" keyword is known as abstract class. In abstract class we can keep abstract method(without body) and non-abstract method(with body).

For example:

abstract class Demo
{
abstract void show();//abstract method
void show(){}//non-abstract method
}

(4) Can we create instance of abstract class?

No, We cannot create an instance of an abstract class.

(5) Can we define abstract class without abstract method?

Yes, We can define abstract class without abstract method.

(6) Can we declare abstract method in non-abstract class?

No, We can't declare abstract method in non-abstract class.

For example:

class Demo
{
abstract void show();
}

Above example will throw compile time error.


(7) What is interface in  java? 

An interface in java is a blueprint of a class that have static constants and abstract method by default.

(8) Why we use interface in java?

In java we use interface so that we can achieve fully abstraction because through abstract class we can't achieve full abstraction.


(9) Can we create instance of interface?

No, We cannot create object of both an interface and abstract class.

(10) Can we declare abstract method as static?

No, We can't use static keyword with abstract method.

(11) Can we declare abstract method as final?

No, We cannot use final keyword with abstract class.


(12) Can we declare abstract method as private?

No, We cannot declare abstract method as private.

(13) Can we use public, protected and default modifiers with abstract method?

Yes, We can use public, protected and default modifiers with abstract method.

(14) Can we declare local inner class as abstract?

Yes, We can declare local inner class as abstract.

(15) Method in interface are by default public and abstract. true or false?

Yes, It is true.

(16) Data member in interface are by default public, static, and final. true of false?

Yes, It is true.

(17) Can abstract class implements interface in java?

Yes, Abstract class can implement interface.

(18) Can we use abstract keyword with constructor?

No, We can't use abstract keyword with constructor.

(19) Abstract classes can be nested. true or false?

Yes, Abstract classes can be nested.


(20) Can abstract class have constructor in java?

Yes, We can declare constructor in abstract class.

(21) Difference between abstraction and encapsulation in java?


(22) What is the difference between abstract class and interface?

You can click on this link to see what is the difference between abstract class and interface in java with example 


(23) Can abstract method declaration include throws clause?

Yes.


(24) What will happen if we do not override all the abstract methods in sub-class?

It will throw compile-time error. We have to override all the abstract method in sub-class. If you do not want to override all the abstract method in sub-class then you have to make your sub-class as abstract class.

Read More:

Java Interview Questions on Interface.
Java OOPS Interview Questions.
Java Inheritance Interview Questions.
Java Super Keyword Interview Questions.
Java Abstract Class with Example.
Java Interface with Example.

This java abstraction interview questions will help you in java interviews. 

Share:

1 comment:

  1. Nice and useful java interview questions

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on Google+

Follow javatutorial95 on twitter

Popular Posts

Get Updates By Email

Link

Translate