Java Interview questions and answers for Freshers

Q1). Explain that what is Java?
Java is an object programming language that was premeditated to moveable across several platforms and operating structures. This language was developed by Sun Microsystems. Java is exhibited after the C++ programming language and comprises special structures that make it perfect for programs on the Internet.
Q2). Explain the meaning of static in Java?
Static stands for one per class, not one for every object no matter how various instances of a class might occur. This entails that you can use them deprived of generating an instance of a class.
Static methods are indirectly final since overriding is done grounded on the type of the object and static approaches are involved in a class, not an object.
A static technique in a superclass can be followed by an alternative static method in a subclass if the unique method was not acknowledged final.
Though, you can’t overrule a static technique with a non-static technique. In other words, you can’t do modification in a static technique into an illustration method of a subclass.
Q3). Why is Java perceived to be platform independent?
This is because platform independent is the term that means “write once run anywhere”. Java is referred to because of its bytecodes that have the capacity to run on any system or device whatsoever irrespective of the underlying operating system.
Q4). Why is JAVA not 100% object-oriented?
Java is not cent percent object-oriented because it utilizes eight types of primitive datatypes named as boolean, byte, char, int, float, double, long, short which are not objects.
Q5). Explain constructors in JAVA?
In the Java framework, the constructor is the term that refers to a block of code which is usually used to initiate an object. It should have the same name as that of its class.
Q6). How many types of constructors are there in JAVA?
There are two types of constructors in JAVA:
Default constructor
Parameterized constructor
Q7). What is a singleton class and how can we make a class singleton?
Singleton class is a class whose only one instance can be created at any given time, in one JVM. A class can be made singleton by making its constructor private.
Q8). Is it possible to override a private or a static method in Java?
No, there is no provision to override a private or static method in Java. However, you can use the method hiding approach in extraordinary cases.
Q9). What do you mean by association?
Association refers to a relationship where all the objects of the class have got their own lifecycle and there is no owner as such. These relationships or associations as we call them can be one to one or one to many or many to one or many to many.
Q10). Explain the concept of aggregation in JAVA?
Aggregation is a concept in JAVA for a specialized form of Association where all the objects have got their own lifecycle but there is ownership and the child object cannot belongs to another parent object in any manner.

Leave a Reply