JAVA

Interview Questions  for freshers

Q1. What is Java?

 Java is a high-level, object-oriented programming language and its platform-independent, allowing it to run on any platform.

It is widely used for developing desktop, mobile, enterprise-level, and web applications.

Q2. What is a class in  Java?

A class is a blueprint for creating objects in Java.

It defines the properties and behaviours that an object will possess.

Q3. Why is Java a platform independent language?

Java is platform independent because it converts code to byte code.

Byte code is platform-independent and can run on multiple systems.

Q4. Which class is a superclass of all classes?

The root class for all Java classes is java.lang. Object.

All non-primitive types and arrays are inherited from this class, either directly or indirectly.

Q5. What are instance and local variables?

Instance variables are accessible by all class methods, while local variables are restricted to a block, function, or constructor.

Instance variables describe an object's properties and remain bound to it, while local variables have limited scope within a block or method.

Q6. What are Java's access specifiers?

Public

Protected

Private

Default

Q7. How many types of constructors are used in Java?

Default Constructor

Parameterized Constructor

Q8. Name the Memory Allocations available in Java

Class Memory

Heap Memory

Stack Memory

 Program Counter-Memory

Native Method Stack Memory

Q9. What is a package in Java?

Java packages group related classes, like folders in a file directory.

Packages help avoid naming conflicts and improve code maintainability.

Q10. Difference between a constructor and a method in Java?

Constructor: Used to create and initialize an object of a class.

Method: A block of code that can be called multiple times within a class.

Preparing to attend interview for Java?

Learn with Whizlabs!