Core Java interview questions

Core Java interview questions Download Core Java interview questions PDF

Core Java interview questions

Inheritance in Java is an important concept in any object-oriented programming language. Using inheritance, one class is allowed to inherit the properties and features of another class. The properties and features include the fields and the methods. Inheritance takes place with the help of keyword “extends”. There is a superclass whose features are inherited. It is also known as the base class or parent class. There is a subclass which inherits the properties of the base class. It is also known as derived class, extended class or the child class. Inheritance also supports the concept of “reusability”.
A constructor in Java is basically a block of code which initializes the objects which are newly created. Although it resembles an instance method in java it is not since it does not return any value or have a return type. People usually refer constructors as special types of methods in java. Constructors and methods are two different things. In java, or in any other object-oriented programming language, a constructor has the same name as that of the class. There are basically 3 types of constructors in java. They are: –
  • Default constructors
  • Parameterized constructors, and
  • Non-parameterized constructors.

The purpose of using multithreading is to make multiple lightweight processes running simultaneously because threads have a plus point, they are lightweight process. Multiple processes not only reserve the memory space but also make the increase the work complication as well. To eliminate the memory space issue and complications we prefer multithreading because they used a shared memory area which saves memory and performs better memory management.

It is not possible in java to write the definition of a function inside another function. It is like we are creating confusion for the compiler in making a decision for which function definition part to terminate and which is not. It is not recommended and not professional. For this purpose, we can use Lambda expression.

Note: Lambda expression is introduced in Java 8 which can be created without belonging to any class.

An abstract class is a class in java which contains the abstract keyword in its declaration. It can have both abstract and non-abstract methods. The abstract class can have the public, private, protected, constant and default variables. This class needs to be extended and we need to implement the methods. This class can’t be instantiated. A class can be declared as an abstract class if it has at least one abstract method. An abstract class has at least one virtual function. Keyword “abstract” is used to make a class abstract.