Java Interview Questions with Answer VOL.- 1

Are you preparing for JAVA interview questions?

Here are few basic JAVA interview questions. These questions are asked in various JAVA interviews to know a candidates basic java programming skill.

Here are some important Java Interview Questions with Answer

Q.1 What is the difference between a JDK and a JVM?

Ans: JDK is Java Development Kit. JDK includes execution and used for development while JVM is a run time environment. We can not compile our source files using a JVM.

Q.2 Name the base class of all classes?

Ans: java.lang.Object

Q.3  Is Java a pure object oriented programming language?

Ans: Primitive data types are used by Java therefore it is not a pure object oriented programming language.

Q.4  What are transient variables in java?

Ans:  Transient variables are those variables that cannot be serialized.

Recommended for you: 8 TIPS TO HANDLE A PHONE INTERVIEW SUCCESSFULLY  – 2017

Q.5 What is Inheritance principle.

Ans: Inheritance is an important principle in OOPs. An object acquires the properties of another object by using inheritance principle.

Q.6  Tell different access Specifiers in Java?

Ans: Different specifiers are:

Private
Defaults
Public
Protected

Q.7  What are local variables?

Ans: Those variables which are declared within a block of code are local variables. These variables should be initialized before accessing them.

Q.8 How can we define a constant variable in Java?

Ans: The variable should be declared as static and final.

Q.9 In all java classes, should a main() method must be compulsorily declared ?

Ans:  main() method should be defined only when source class is a java application.

Recommended for you: SQL SERVER INTERVIEW QUESTIONS [SQL TUTORIAL] VOL.-1

Q.10  Tell the use of the finally block in java?

Ans: It is the block of code that executes always. This block of code will execute even when an exception is occurred. When the user calls System.exit() this block of code is not executed.

Q.11  Tell the principles of OOPS.

Ans: oops has three main principals :
Polymorphism
Encapsulation
Inheritance.

Q.12 Tell the return type of the main() method?

Ans: Main() method is declared void it doesn’t return anything.

Click Here for More Interview Questions

 

Q.13 Describe a package?

Ans: It is a collection of related interfaces and classes. In a ‘java’ class package declaration should be first statement.

Q.14 Which package is imported by default?

Ans: By default java.lang package is imported even without a package declaration.

Q.15  Give some examples of final classes defined in Java API?

Ans:  java.lang.Math, java.lang.String are final classes.

Q.16  Is it possible to declare a static variable inside a method?

Ans: Static varaibles are can’t be declared inside a method because Static varaibles are class level variables. If we declare them inside a method, the class will not compile.

Q.17  Is it possible to declare an abstract class final?

Ans:  No it is not possible. It will result in compile time error.

Q.18  Is it possible to declare a class as protected?

Ans: No we can not declare a class as protected. We can declare  methods as protected.

Q.19  Describe the access scope of a protected method?

Ans: We can access a protected method by the classes within the same package and also by the subclasses of class in any package.

Q.20  Why main() method is declared static?

Ans: main() method is declared as static because it is called by the JVM even before the instantiation of the class.

Q.21 Tell the arguments of main() method?

Ans:  It accepts an array of String object as argument.

Q.22 Is it possible to overload a main() method ?

Ans: We can overload main() method, we can have any number of main() methods having different method signature and implementation in the class.

Q.23 Explain List interface ?

Ans:  It is an ordered collection of objects.

 

Click Here for More Interview Questions

Add a Comment

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

Copy Protected by Chetan's WP-Copyprotect.