HomeJava

Java – Interview Questions and Answers – Part 6

Java – Interview Questions and Answers – Part 6

1) What is the difference between static variables and instance variables?

Answer: The below is the answer for this question:

static variables are common variables who’s values will be stored in Class memory.

instance variables are object specific variables who’s values will be stored in individual object’s memory.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


2) What is the result of specifying final modifier with Classes, Variables and Methods?

Answer: The below is the answer for this question:

final modifier can be specified to Classes, Variables and Methods.

  • On specifying to Classes, the Classes cannot be inherited (i.e. Child Classes cannot be created).
  • On specifying to Variables, the initially assigned values to the variables cannot be changed.
  • On specifying to Methods, the methods cannot be overridden in child classes.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


3) What are abstract methods?

Answer: The below is the answer for this question:

methods specified with abstract modifier are known as abstract methods.

  • abstract methods won’t have method body.
  • abstract methods needs to be created under abstract class.
  • All the methods in an Interface are by default abstract.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


4) Can we create abstract methods inside non-abstract classes?

Answer: The below is the answer for this question:

No, we cannot create abstract methods inside non-abstract classes.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


5) What are abstract classes?

Answer: The below is the answer for this question:

The Classes that are specified with abstract non-access modifier are known as abstract classes.

abstract classes are recommended for partial implementation, as these class can have both abstract and non-abstract methods.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


6) Can an abstract class have both abstract and non-abstarct methods?

Answer: The below is the answer for this question:

Yes, abstract classes are meant for partial implementation and hence they can contain both abstract and non-abstract methods.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


7) How to implement the abstract methods of abstract classes?

Answer: The below is the answer for this question:

We have to create the child classes for the abstract classes for implementing its abstract methods.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


8) Can we create objects for abstract classes?

Answer: The below is the answer for this question:

No. Objects cannot be created for abstract classes.ax

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


9) What is the parent class of all the classes in Java?

Answer: The below is the answer for this question:

Object Class is the parent class of all the classes in Java.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


10) What is the default package in Java?

Answer: The below is the answer for this question:

java.lang is the default package in Java.

  • Hence we don’t have to import the classes like System or String etc., as they belong to java.lang package.
  • For using the classes which are from a different package other than java.lang, we have to import those classes.
  • File class in Java, doesn’t belong to java.lang package, hence we have to import this class for using it in the Java programs.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


Please leave your questions/comments/feedback below.

Happy Learning 🙂

Arun Motoori ( www.QAFox.com )

Comments (0)

Leave a Reply

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