Core Java - Interview Questions and Answers VOL-I

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

Ans:  JDK is Java Development Kit which is for development purpose and it includes execution environment also.
But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

Q.2  What is the base class of all classes?

Ans:  java.lang.Object

Q.3  Is Java a pure object oriented language?

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

Q.4  What are transient variables in java?

Ans:  Transient variables are variable that cannot be serialized.

Q.5  Explain the Inheritance principle.

Ans:  Inheritance is the process by which one object acquires the properties of another object. 

Q.6  What are Access Specifiers available in Java?

Ans:  Access specifiers are keywords that determines the type of access to the member of a class. These are:

    Public
    Protected
    Private
    Defaults

Q.7  What are local variables?

Ans:  Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.

Q.8  How to define a constant variable in Java?

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


Q.9  Can we call finalize() method ?

Ans:  Yes.  Nobody will stop us to call any method , if it is accessible in our class. But a garbage collector cannot call an object's finalize method if that object is reachable.


Q.10  Should a main() method be compulsorily declared in all java classes?

Ans:  No not required. main() method should be defined only if the source class is a java application.

Q.11  What is the use of the finally block?

Ans:  Finally is the block of code that executes always. The code in finally block will execute even if an exception is occurred. finally will not execute when the user calls System.exit().


Q.12  Describe the principles of OOPS.

Ans:  There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation. 

Q.13  What is the return type of the main() method?

Ans:  Main() method doesn't return anything hence declared void.


Q.14  What is a package?

Ans:  Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.

Q.15  Which package is imported by default?

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

Q.16  Can you give few examples of final classes defined in Java API?

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

Q.17  Can we declare a static variable inside a method?

Ans:  Static varaibles are class level variables and they can't be declared inside a method. If declared, the class will not compile.

Q.18  Can a abstract class be declared final?

Ans:  Not possible. An abstract class without being inherited is of no use and hence will result in compile time error.

Q.19  Can a class be declared as protected?

Ans:  A class can't be declared as protected. only methods can be declared as protected.

Q.20  What is the access scope of a protected method?

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

Q.21  Why is the main() method declared static?

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

Q.22  What is the arguement of main() method?

Ans:  main() method accepts an array of String object as arguement.

Q.23  Can a main() method be overloaded?

Ans:  Yes. You can have any number of main() methods with different method signature and implementation in the class.

Q.24  What is List interface ?

Ans:  List is an ordered collection of objects.

Q.25  Can a main() method be declared final?

Ans:  Yes. Any inheriting class will not be able to have it's own default main() method.

Q.26  Does the order of public and static declaration matter in main() method?

Ans:  No. It doesn't matter but void should always come before main().

Q.27  What is the difference between yield() and sleep()?

Ans:  When a object invokes yield() it returns to ready state. But when an object invokes sleep() method enters to not ready state.

Q.28  Can a source file contain more than one class declaration?

Ans:  Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.

Q.29  Explain the Polymorphism principle.

Ans: The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods". 

Q.30  What is an abstract method ?

Ans:  An abstract method is a method that don't have a body. It is declared with modifier abstract.

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Hostgator Coupon Code