Top Java Interview Questions and Answers

Posted by cyber success on June 28th, 2019

1. What is JDK?

Ans: JDK is an acronym for Java Development Kit. It is a bundle of software components that is used to develop Java-based applications includes JRE and the compilers and tools (like JavaDoc, and Java Debugger) to create and compile programs.

2. Which is the latest Version of Java?

Ans:  Java SE 12  release date 2019-03-19,  feature contains Initial release

Java SE 12.0.1 release date 2019-04-16, feature contains New Japanese Era Name & Security fixes

3. How can you access the static global variable of a class?

Ans: You need an extern keyword.
For example, we have one global variable named an in main.cpp

  1. // main.cpp
  2. int a = 1;
  3. int main()
  4. {
  5. // do something...
  6. }
  7.  

We want to access the global variable an in MyClass.cpp, we should use extern.

  1. // MyClass.cpp
  2. extern int a;
  3.  
  4. MyClass::MyClass()
  5. {
  6. a = 3; // Change the global variable
  7. }

4. What is Diamond Problem?

Ans: The diamond problem refers to an ambiguity that brews due to allowing multiple inheritance. In Java, multiple inheritance is not allowed for classes and permitted only for interfaces to eliminates this serious issue.

5. When IIB's will be executed?

Ans: IIBs are executed before constructors. They run each time when the object of the class is created.

6. What is the rule to be followed by the sub-class of an abstract class?

Ans:

  1. An abstract class must be declared with an abstract keyword.
  2. It can have abstract and non-abstract methods.
  3. It cannot be instantiated.
  4. It can have constructors and static methods also.
  5. It can have final methods which will force the subclass not to change the body of the method.

7. What does a method's return type signify?

Ans: Return is a reserved keyword in Java i.e, we can’t use it as an identifier. It is used to exit from a method, with or without a value.

Return can be used with methods in two ways:

  1. Methods returning a value: For methods that define a return type, the return statement must be immediately followed by the return value.
  2. Methods not returning a value: For methods that don’t return a value, the return statement can be skipped.

8. Recursion while constructor overloading will result in compile time or run time error

Ans: Run time error

9. What is Auto Upcasting and Explicit Downcasting?

Ans: Converting a subclass type to a superclass type is known as up casting.

Example-

class Super {

   void Sample() {

      System.out.println("method of super class");

   }

}

public class Sub extends Super {

   void Sample() {

      System.out.println("method of sub class");

   }

   public static void main(String args[]) {

      Super obj =(Super) new Sub(); obj.Sample();

   }

}

Converting a superclass type to a subclass type is known as downcasting.

Example-

class Super {

   void Sample() {

      System.out.println("method of super class");

   }

}

public class Sub extends Super {

   void Sample() {

      System.out.println("method of sub class");

   }

   public static void main(String args[]) {

      Super obj = new Sub();

      Sub sub = (Sub) obj; sub.Sample();

   }

}

10. What is JRE?

Ans: JRE stands for “Java Runtime Environment” and may also be written as “Java RTE.” The Java Runtime Environment provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files.

Hope this blog regarding java interview questions will help to crack the interview with ease. If you want to learn the practical concept of java with hands-on experience then enroll in our Java Course in Pune.

Like it? Share it!


cyber success

About the Author

cyber success
Joined: June 20th, 2019
Articles Posted: 30

More by this author