Java Interview Questions and Answers – Part 2

This post is continuation for previous post on Java Interview Questions and Answers. We will try to focus only the concepts that are required for Hadoop Developers and Hadoop Administrators.

Java Interview Questions and Answers:
1. What is the difference between a JDK and a JRE ?

JDK, Java Development Kit is for development purpose and it includes execution environment also. But JRE is purely java run time environment and hence we will not be able to compile our source files using a JRE.

2. Is Java a pure object oriented language ?

No. Java uses primitive data types and hence is not a pure object oriented language.

3. Are arrays primitive data types ?

No. In Java, Arrays are objects.

4. Can a class declared as private be accessed outside it’s package ?


5. What is the access scope of a protected method ?

A protected method can be accessed by the classes within the same package  or by the subclasses of the class in any package.

6. What is the purpose of declaring a variable as final ?

A final variable’s value can’t be changed. final variables should be initialized  before using them.

7. What is the impact of declaring a method as final ?

A method declared as final can’t be overridden. A sub-class can’t have the same method signature with a different implementation.

8. When we don’t want our class to be inherited by any other class. What should we do?

We should declare the class as final. But we can’t define our class as final, if it is an abstract class. A class declared as final can’t be extended by any other class.

9. Can we declare a static variable inside a method ?

No. Static variables are class level variables and they can’t be declared inside a method. If declared, the class will not compile.

10. What is an Abstract Class ?

A Class which doesn’t provide complete implementation is known as an abstract class. Abstract classes enforce abstraction.

11. Can an abstract class be declared final?

No. An abstract class without being inherited is of no use and hence will result in compile time error.

12. What is the use of an abstract variable?

Variables can’t be declared as abstract. only classes and methods can be declared as abstract.

13. Can we create an object of an abstract class?

No. Abstract classes can’t be instantiated.

14. Can an abstract class be defined without any abstract methods?

Yes it’s possible. This is basically to avoid instance creation of the class.

15. Class C implements Interface I containing method m1 and m2 declarations. Class C has provided implementation for method m2. Can i create an object of Class C?

No. It is not possible. Class C should provide implementation for all the methods in the Interface I. Since Class C didn’t provide implementation for m1 method, it has to be declared as abstract. Abstract classes can’t be instantiated.

16. Can a method inside an Interface be declared as final?

No. Doing so will result in compilation error. public and abstract
are the only applicable modifiers for method declaration in an interface.

17. Can an Interface implement another Interface?

No. Interfaces doesn’t provide implementation hence an interface cannot implement another interface.

18. Can an Interface extend another Interface?

Yes an Interface can inherit another Interface, so an Interface can extend more than one Interface.

19. Can a Class extend more than one Class?

No. A Class can extend only one class but can implement any number of Interfaces.

20. Can an Interface be final?

No. Doing so will result in compilation error.

A few more java interview questions and answers are continued in the next page.

Profile photo of Siva

About Siva

Senior Hadoop developer with 4 years of experience in designing and architecture solutions for the Big Data domain and has been involved with several complex engagements. Technical strengths include Hadoop, YARN, Mapreduce, Hive, Sqoop, Flume, Pig, HBase, Phoenix, Oozie, Falcon, Kafka, Storm, Spark, MySQL and Java.

Leave a comment

Your email address will not be published. Required fields are marked *

Review Comments
default gravatar

I am a plsql developer. Intrested to move into bigdata.

Neetika Singh ITA