Top 10  Interview Questions for Freshers on Core Java

Top 10 Interview Questions for Freshers on Core Java

Java Language   /   Mar 25th, 2023   /  A+ | a-

Q1)  What makes Java a platform-independent programming language?

Ans:- Java is platform-independent because it provides the feasibility to run and compile the program in one platform and execute the program on any other platform of your choice.
 

Q2)Would it be correct to say that Java is not 100% Object-oriented?

Ans:- Yes, it would be correct to say that Java is not 100% Object-oriented because it utilizes eight kinds of primitive data types and they are - Boolean, byte, char, int, float, double, long, short. These data types are not objects.
 

Q3). What is a constructor in Java?

Ans:- A constructor is a block of code that is used in a Java environment to initialize an object. It carries the same name that you had given to the class. A Java constructor is automatically called when an object is created.


 

Q4).  Differentiate between a constructor and a method? Can we mark constructors final?

Ans:- A constructor constructs the value, by providing data for the object. It is a special type of method that is used to initialize the object. The constructor has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. A method can be invoked using the dot operator and has its own name, and a return type. No, declaring the constructor as final is not possible.


 

Q5).  What is a class in Java?

Ans:- A class, in the environment of Java, are some templates that are used for object creation, and to define certain object data types and their methods.
 

Q6). What is the final class?

Ans:- A final class is a constant value of a final variable. Extending A final class is not possible ie., final class may not be subclassed. A final method cannot be overridden when its class is inherited.
 

Q7).What is a wrapper class?

Ans:- The classes that “wrap” the primitive data type into an object of that class are called Java wrapper classes.
 

Q8). What is an abstract class?

Ans:- Abstract serves as a template. In order to use an abstract class, it must be extended or subclassed. An abstract class may not be instantiated. Any class with an abstract method is abstract itself, hence is declared as such.


 

Q9). What is the purpose of garbage collection in Java, and when is it used?

Ans:- The main purpose of garbage collection is to analyze a program, identify and discard the objects that are no longer needed. It is helpful as the resources can be reclaimed and reused. A Java object is subjected to garbage collection when the object is not reachable to the program in which it is used.


 

Q10). What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?

Ans:- When the main() method is declared as private, the program compiles but during runtime it shows “main() method not public.” Message. When the static modifier is removed from the signature of the main() method, the Program compiles but at runtime throws an error “NoSuchMethodError”.


Mentor - Mahadev Gochade
Intormation and research are sources from internet.
Tags:  #java_interview_questions #java_Programming #nitsglobal #website #blog
 

Top