Home » Interview Preparation » 60 Java Interview Questions for Freshers (0–1 Year) – Crack Your First Tech Job

60 Java Interview Questions for Freshers (0–1 Year) – Crack Your First Tech Job

Are you a Java fresher with 0–1 year of experience and looking to crack your first technical interview? You’re in the right place! Whether you’re targeting top MNCs like TCS, Infosys, Cognizant, Wipro, Accenture, or Capgemini, or any mid to small company and startups, this is the most comprehensive and beginner-friendly Java interview question bank available online.

In this blog, you’ll find the Top 60 Basic Java Interview Questions and Answers, handpicked to help freshers clear technical face to face Java interview rounds with confidence. These questions cover all essential Java concepts including:

  • Core Java fundamentals
  • Object-Oriented Programming (OOPs)
  • Data types and control statements
  • Exception handling
  • String operations
  • Classes, objects, and more

🎯 This is the best resource to crack MNC interviews, specially crafted by Prakash Kumar, a Java and Spring Boot expert with over 8 years of real-world industry experience. These are the questions that actually asked during the interview. Each answer is explained in detail. This is perfect for beginners who want to build a strong foundation in Java. This blog is designed to provide crystal-clear explanations, real interview trends, and practical insights for freshers.

💡 Want to strengthen your hands-on skills too?

👉 Check out our collection of Java Coding Questions for Freshers and Pattern Programs in Java — both of which are frequently asked in interviews and help demonstrate your logic-building ability.

Don’t waste time jumping between random YouTube videos or outdated notes — this is your one-stop solution to prepare smarter, not harder.

Let’s dive right in and get you interview-ready! 💪

Core Java – Basics

1. What is Java?

Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995 and now owned by Oracle. It is used to build applications for web, desktop, and mobile platforms. Java’s main philosophy is “Write Once, Run Anywhere” (WORA), which means compiled Java code can run on all platforms that support Java without the need for recompilation.

Java is both compiled and interpreted. First, Java source code is compiled into bytecode using the Java Compiler (javac). This bytecode is not directly executed by the operating system but is run by the Java Virtual Machine (JVM), which makes Java platform-independent. This means the same .class file can run on Windows, Linux, or macOS without any changes.

2. What are the features of Java?

Java comes with various features that make it a preferred language for both beginners and enterprise-level development. These features of Java are it is platform independent, object-oriented, simple and familiar, secure, robust, multithreaded, and architecture-neutral.

3. What is the JVM, JRE, and JDK?

  • JVM: Java Virtual Machine runs Java bytecode.
  • JRE: Java Runtime Environment provides libraries and JVM.
  • JDK: Java Development Kit includes JRE and tools to develop Java programs.

4. What is the difference between JDK and JRE?

JDK is used for developing and running Java programs, while JRE is used only for running Java programs.

JDK (Java Development Kit): JDK is a complete package used to develop, compile, debug, and run Java applications, and it includes the JRE along with development tools like the compiler and debugger.

JRE (Java Runtime Environment): JRE provides only the runtime environment needed to execute Java programs and does not include development tools.

5. What is bytecode in Java?

Bytecode is an intermediate code generated after compiling Java code. JVM executes bytecode. In detail we can explain it as Bytecode is the intermediate code generated after compiling Java source code using the javac compiler.

When a .java file is compiled, it is converted into a .class file containing bytecode. This bytecode is not machine code but a platform-independent representation that can be understood by the Java Virtual Machine (JVM).

6. Is Java platform-independent? Why?

Yes, because Java code is compiled into bytecode which runs on any system using the JVM. When you write Java code, the .java file is compiled by the javac compiler into a .class file. This .class file contains bytecode, which is not tied to any specific hardware or operating system. The JVM acts as a layer between the bytecode and the underlying platform. So, as long as a device has a compatible JVM installed, it can run the bytecode without needing recompilation.

7. What is the difference between Java and C++?

One major difference is that, Java is platform-independent, uses automatic memory management, and doesn’t support pointers. C++ is platform-dependent and uses manual memory management.

In summary:

  • Java is platform-independent; C++ is platform-dependent.
  • Java has automatic garbage collection; C++ does not.
  • Java does not support pointers; C++ does.
  • Java avoids multiple inheritance with class; C++ supports it directly.

8. What is a class and an object in Java?

Class: A class is a blueprint or template that defines the structure (fields/variables) and behavior (methods) of objects. You can think of a class as a design or plan.

Object: An instance of a class. When you create an object using the new keyword, Java allocates memory for it and allows you to interact with it. Each object has its own copy of the class’s fields and can use the class’s methods.

9. What is constructor in Java?

Constructor is a method used to initialize objects. They have the same name as the class and does not have a return type, not even void.

When you use the new keyword to create an object, Java automatically calls the constructor of the class to create an object. If no constructor is defined by the programmer, Java provides a default constructor that has no arguments.

There are two types of constructors in Java:

  1. Default constructor – No parameters.
  2. Parameterized constructor – Accepts parameters to set initial values.

10. What is method overloading and method overriding?

Method Overloading: Same method name but different parameters of the methods in the same class. Method Overloading occurs when multiple methods in the same class have the same name but different parameters (different number or type of parameters). It is a type of compile-time (static) polymorphism. Overloading is useful when the same action can be performed in different ways.

Method Overriding: Same method in a subclass with different behavior. Method Overriding happens when a subclass provides a specific implementation of a method that is already defined in its parent class. It uses the same method name, same parameters, and same return type. This is known as runtime (dynamic) polymorphism.

11. What is the difference between static and non-static methods?

Static Method: A static method belongs to the class itself, not to any specific object created from that class. It is shared among all objects and can be called without creating an instance of the class. Static methods are defined using the static keyword. They are often used for utility or helper methods, like Math.sqrt(). In short you can say that Static methods belong to the class and can be called without creating an object.

Non-Static Method: A non-static method, on the other hand, belongs to an object of the class. To call a non-static method, you must create an object first using the new keyword. These methods can access both instance and static variables of the class. In short you can say that Non-static methods belong to objects

12. What is the main method signature in Java?

The main() method is the entry point of any standalone Java application. Without it, the JVM wouldn’t know where to begin executing your program. Its standard signature is:

public static void main(String[] args)

Let’s break it down:

  • public – This means the method can be called from anywhere. The JVM needs to call it from outside the class.
  • static – It can be run without creating an object of the class. The JVM calls it directly without instantiating the class.
  • void – It doesn’t return any value.
  • main – It’s the method name that JVM looks for to start execution.
  • String[] args – It accepts command-line arguments as a string array.

13. What is the difference between ‘==’ and ‘.equals()’ in Java?

== compares object references and .equals() compares the actual content of objects.

== Operator

The == operator is used to compare primitive types and object references. For primitives (like int, float, char), it compares the actual values:

int a = 5;
int b = 5;
System.out.println(a == b);  // true

But when used with objects, == checks whether both references point to the same object in memory, not whether their contents are the same:

String s1 = new String("Java");
String s2 = new String("Java");
System.out.println(s1 == s2);  // false

.equals() Method

The .equals() method is used to compare the content (logical equality) of two objects. Many classes (like String) override it to compare actual data instead of memory reference.

System.out.println(s1.equals(s2));  // true (contents are equal)

14. What are primitive data types in Java?

Java is a statically typed language, which means every variable must have a declared type. Java has 8 primitive data types, which are not objects and represent raw values.

  • boolean – stores only two values: true or false.
  • byte – 8-bit signed integer, range: -128 to 127.
  • short – 16-bit signed integer, range: -32,768 to 32,767.
  • int – 32-bit signed integer, commonly used. Range: -2^31 to 2^31-1.
  • long – 64-bit signed integer. Use for larger numbers.
  • float – 32-bit floating-point number, used for decimal values (less precision).
  • double – 64-bit floating-point number, more precise than float.
  • char – 16-bit Unicode character, stores single characters like ‘A’, ‘1’, or ‘$’.

15. What are wrapper classes?

In Java, wrapper classes are object representations of primitive data types. They “wrap” the primitive types into objects so they can be used where objects are required, like in collections (ArrayList, HashMap, etc.) or generics.

Each primitive type has a corresponding wrapper class:

  • byteByte
  • shortShort
  • intInteger
  • longLong
  • floatFloat
  • doubleDouble
  • charCharacter
  • booleanBoolean

OOPs Concepts

16. What are the four pillars of OOP?

Inheritance, Polymorphism, Abstraction, Encapsulation.

17. What is inheritance in Java?

Inheritance allows a class to inherit properties and methods from another class.

Types of inheritance in Java:

  1. Single inheritance (one parent, one child)
  2. Multilevel inheritance (a child class becomes parent of another)
  3. Hierarchical inheritance (one parent, multiple children)

Java does not support multiple inheritance using classes to avoid ambiguity (diamond problem), but it supports it using interfaces.

18. What is Polymorphism? Explain types.

Polymorphism means “many forms.” In Java, it allows the same method or object to behave differently depending on the situation.

Java supports two types of polymorphism:

  • Compile-time (method overloading)
  • Run-time (method overriding)

19. What is encapsulation?

Encapsulation is wrapping data and code together. Achieved using private variables and public methods.

In Details, Encapsulation is the process of wrapping data (variables) and methods that operate on the data into a single unit (class), and restricting direct access to some of the object’s components.

This is achieved using:

  • Private fields
  • Public getter and setter methods
class Person {
    private String name;
    public void setName(String name) {
        this.name = name;  // setter
    }
    public String getName() {
        return name;  // getter
    }
}

Here:

  • The name variable is private.
  • It can only be accessed or modified using public methods (getName() and setName()).

20. What is abstraction?

Abstraction means hiding internal implementation details and showing only essential information of an object. It focuses on what an object does rather than how it does it.

In Java, abstraction is achieved using:

1. Abstract Classes

  • Can have abstract and non-abstract methods
  • Used when classes share common behavior with partial implementation

2. Interfaces

  • Contains only abstract methods (and default/static methods in Java 8+)
  • Used to achieve full abstraction and multiple inheritance

21. What is the difference between abstraction and encapsulation?

Abstraction is about hiding the “how” and showing only what is necessary.

Encapsulation is about hiding the data and controlling access to it.

22. Can Java support multiple inheritance? If not, how does it achieve it?

Java doesn’t support multiple inheritance with classes, but it supports it using interfaces.

23. What is the role of the super keyword?

The super keyword in Java is used to refer to the immediate parent class of the current object. It helps in:

  • Accessing parent class fields if they are hidden by subclass fields.
  • Accessing parent class methods that are overridden in the child class.
  • Calling the parent class constructor using super() in the subclass constructor.

In short, super helps in maintaining the inheritance relationship by giving access to parent class members.

24. What is the this keyword in Java?

The this keyword in Java is a reference variable that refers to the current object of the class. It is mainly used within instance methods or constructors to eliminate confusion between instance variables and parameters.

class Student {
    String name;
    Student(String name) {
        this.name = name;  // "this.name" refers to the instance variable
    }
}

25. What is the difference between final, finally, and finalize()?

final prevents modification, finally ensures execution after exception handling, and finalize() is called before garbage collection to clean up resources.

final

final is a keyword used to make variables constant, methods non-overridable, and classes non-inheritable.

  • Final variable → value cannot be changed
  • Final method → cannot be overridden
  • Final class → cannot be extended

finally

finally is a block used with try–catch that always executes, whether an exception occurs or not.
It is mainly used for cleanup operations like closing files or database connections.

finalize()

finalize() is a method called by the Garbage Collector before an object is removed from memory.
It is used to perform cleanup tasks before object destruction (now deprecated in modern Java).

Control Flow & Operators

26. What are different types of loops in Java?

Java supports three main types of loops:

  • do-while loop – similar to while, but the condition is checked after the loop runs at least once.
  • for loop – used when the number of iterations is known.
  • while loop – used when the condition is checked before the loop runs.

27. What is the difference between break and continue?

The break statement ends the loop immediately, while the continue statement skips the current iteration and moves to the next one.

Using break:

for (int i = 1; i <= 5; i++) {
    if (i == 3) {
        break;
    }
    System.out.println(i);
}
// Output: 1 2

Using continue:

for (int i = 1; i <= 5; i++) {
    if (i == 3) {
        continue;
    }
    System.out.println(i);
}
// Output: 1 2 4 5

break stops the loop completely when i == 3.
continue skips printing 3 but continues with the rest of the loop.

28. What is a switch statement in Java?

A switch statement in Java is a control flow statement that allows you to execute one block of code among many options based on the value of an expression.

It works like a cleaner alternative to multiple if-else statements when you are checking a variable against many constant values.

Switch Statement Code Snippet

switch (expression) {
    case value1:
        // code block
        break;
    case value2:
        // code block
        break;
    // ...
    default:
        // default block
}

29. What is the ternary operator?

The ternary operator in Java is a shorthand way of writing an if-else statement. It is also known as the conditional operator and uses the ? and : symbols.

Syntax

condition ? expression1 : expression2;
  • If the condition is true, expression1 is executed.
  • If the condition is false, expression2 is executed.

30. What are logical and bitwise operators?

Logical Operators:

Logical operators work with boolean values (true or false). They are commonly used in conditional statements like if, while, etc.

OperatorDescriptionExample (a = true, b = false)
&&Logical ANDa && bfalse
``
!Logical NOT!afalse

Bitwise Operators:

Bitwise operators work with integer data types and operate on the individual bits of values.

OperatorDescriptionExample (a = 5, b = 3)Binary Form
&Bitwise ANDa & b10101 & 0011 = 0001
``Bitwise OR`a
^Bitwise XORa ^ b60101 ^ 0011 = 0110
~Bitwise Complement~a-6~0101 = 1010
<<Left Shifta << 1100101 << 1 = 1010
>>Right Shifta >> 120101 >> 1 = 0010

String Handling

31. What is the difference between String, StringBuffer, and StringBuilder?

String:

  • Thread-safe: Not applicable since it’s immutable.
  • Immutable – Once created, its value cannot be changed.
  • Every modification creates a new object.
String s = "Hello";
s = s + " World"; // New object is created

StringBuffer:

  • Mutable – Can be modified after creation.
  • Thread-safe – Methods are synchronized, so it’s safe in multithreaded environments.
  • Slower than StringBuilder due to synchronization.
StringBuffer sb = new StringBuffer("Hello");
sb.append(" World"); // Same object is modified

StringBuilder:

  • Mutable – Same as StringBuffer.
  • Not thread-safe – No synchronization, so faster than StringBuffer in single-threaded environments.
StringBuilder sb = new StringBuilder("Hello");
sb.append(" World");

Summary Table

FeatureStringStringBufferStringBuilder
MutabilityImmutableMutableMutable
Thread-safeYesYes❌ No
PerformanceSlowestSlowerFastest
Use CaseConstant textMultithreaded changesFast, single-threaded use

Use:

  • String when the content won’t change.
  • StringBuffer when thread safety is needed.
  • StringBuilder when performance matters more than thread safety.

32. Why are strings immutable in Java?

Strings are immutable in Java to make them secure, memory-efficient, thread-safe, and reliable for use in data structures and shared applications.

Main Reasons

  1. Security
    Strings are widely used for sensitive data like passwords, file paths, and network connections.
    Immutability prevents their values from being changed by unauthorized code.
  2. Memory Efficiency (String Pool)
    Because strings cannot change, Java can safely reuse the same string objects from the String Constant Pool, which saves memory.
  3. Thread Safety
    Immutable strings can be shared between multiple threads without synchronization, making them naturally thread-safe.
  4. Reliability in Hash-Based Collections
    Strings are commonly used as keys in HashMap and HashSet.
    Immutability ensures the hash code never changes, so lookups always work correctly.

33. How do you compare two strings in Java?

You can compare two strings in Java using the following methods:

1). equals() – Checks content (case-sensitive):

String s1 = "Hello";
String s2 = "Hello";
System.out.println(s1.equals(s2)); // true

2). equalsIgnoreCase() – Checks content, ignores case:

String s1 = "Hello";
String s2 = "hello";
System.out.println(s1.equalsIgnoreCase(s2)); // true

3). compareTo() – Lexicographically compares:

String s1 = "Apple";
String s2 = "Banana";
System.out.println(s1.compareTo(s2)); // Negative value (Apple < Banana)

34. What is the use of the intern() method in Strings?

The intern() method is used to add a string to the String Constant Pool and return the reference to the pooled string.

If the same string already exists in the pool, it returns the existing reference instead of creating a new one.

This helps in:

  • Saving memory by avoiding duplicate string objects
  • Allowing faster comparison using == since pooled strings share the same reference

Syntax

String str = new String("Hello");
String internedStr = str.intern();

Here:

  • "Hello" is stored in the String Pool
  • internedStr points to the pooled version of "Hello"

Arrays & Collections

35. How do you declare and initialize an array in Java?

In Java, an array is a collection of elements of the same data type. You can declare and initialize it like this:

int[] numbers = {1, 2, 3, 4, 5};

Or using the new keyword:

int[] numbers = new int[5]; // default values will be 0

ArrayList: Resizable, part of the Collection framework.

36. What is the difference between an array and an ArrayList?

Array

An array has a fixed size that must be defined at creation time and cannot be changed later.
It can store both primitive data types and objects, and provides faster access because of less overhead.

ArrayList

An ArrayList is a resizable collection that can grow or shrink dynamically.
It can store only objects (primitives are stored using wrapper classes) and provides many built-in methods like add(), remove(), and contains().

37. What are the main interfaces of the Collection framework?

The main interfaces of the Java Collection Framework are:

  • Map – key-value pairs (not part of Collection interface but part of the framework, e.g., HashMap, TreeMap)
  • List – ordered collection (e.g., ArrayList, LinkedList)
  • Set – unique elements only (e.g., HashSet, TreeSet)
  • Queue – follows FIFO order (e.g., LinkedList, PriorityQueue)

38. What is the difference between List, Set, and Map?

List maintains order and allows duplicates, Set stores only unique elements, and Map stores data as unique keys mapped to values.

List

A List is an ordered collection that maintains insertion order and allows duplicate elements.
Elements can be accessed by their index.

Example: ArrayList, LinkedList

Set

A Set is a collection that does not allow duplicate elements and usually does not guarantee any order.
It is used when you need only unique values.

Example: HashSet, LinkedHashSet, TreeSet

Map

A Map stores data in the form of key–value pairs, where keys must be unique and each key maps to exactly one value.
Values can be duplicated, but keys cannot.

Example: HashMap, Hashtable, TreeMap

39. What is the difference between ArrayList and LinkedList?

ArrayList

An ArrayList uses a dynamic array to store elements. It provides fast random access using index (get()), but insertions and deletions in the middle are slow because elements must be shifted.

LinkedList

A LinkedList uses a doubly linked list to store elements. It provides fast insertions and deletions, but slow random access because elements must be traversed sequentially.

40. What is a HashMap and how does it work?

A HashMap is a part of Java’s Collection Framework that stores data as key-value pairs. It allows one null key and multiple null values, and does not maintain any order.

How HashMap Works?

  • When you put a key-value pair, the key’s hashCode() is computed.
  • That hash code determines the bucket (index) where the pair will be stored.
  • If two keys have the same hash code (collision), they are stored in a linked list (or tree in case of many collisions in Java 8+).
  • When you retrieve a value using a key, the hash code is used to locate the bucket, and then the key is compared using .equals() to find the exact match.

41. What is the difference between HashMap and Hashtable?

FeatureHashMapHashtable
Thread-safe❌ Not synchronized✅ Synchronized (thread-safe)
Performance✅ Faster (no locking)❌ Slower (due to synchronization)
Null keys/values✅ Allows one null key and multiple null values❌ Does not allow null keys or values
Introduced inJava 1.2Java 1.0
Legacy?❌ Not legacy✅ Legacy class

Summary:

  • Use HashMap in single-threaded environments for better performance.
  • Use Hashtable if you need a thread-safe collection but consider using ConcurrentHashMap instead in modern applications.

42. What is the difference between Iterator and ListIterator?

Iterator can traverse a collection only in forward direction and supports only element removal, while ListIterator can traverse both forward and backward and supports adding, removing, and modifying elements during iteration.

FeatureIteratorListIterator
TraversalOnly in forward directionForward and backward traversal
Applicable toAll Collection typesOnly for List (like ArrayList, LinkedList)
MethodshasNext(), next(), remove()hasNext(), next(), hasPrevious(), previous(), add(), remove(), set()
Index Access❌ Not supported✅ Can get index with nextIndex(), previousIndex()
Insert/Update❌ Can’t add or update elements✅ Can add, remove, and update elements during iteration

Summary:

  • Use Iterator for simple, one-direction traversal across any collection.
  • Use ListIterator when working with lists and you need bidirectional access or want to modify elements while iterating.

Exception Handling

43. What is exception handling in Java?

Exception handling in Java is a powerful mechanism to handle runtime errors, allowing the normal flow of the application to continue. It helps catch and manage unexpected events like invalid user input or file not found errors.

Java provides keywords like try, catch, throw, throws, and finally to handle exceptions properly, improve program reliability, and prevent application crashes.

44. What is the difference between checked and unchecked exceptions?

Checked Exceptions: Checked exceptions are verified by the compiler at compile time and must be either caught or declared using throws. They usually occur due to external or recoverable conditions such as file handling or database access (e.g., IOException, SQLException).

Examples: IOException, SQLException, FileNotFoundException

Unchecked Exceptions: Unchecked exceptions occur at runtime and are not checked by the compiler. It does not required to be declared or caught. They are usually caused by programming errors or invalid logic, and handling them is optional.

Examples: NullPointerException, ArithmeticException, ArrayIndexOutOfBoundsException

Key Differences

Checked ExceptionsUnchecked Exceptions
Checked at compile timeChecked at runtime
Must be handled or declaredNo mandatory handling
Caused by external issuesCaused by programming errors

45. What is the use of try, catch, finally?

try: The try block is used to enclose code that may generate an exception and allows the JVM to detect and monitor runtime errors.

catch: The catch block is used to receive and handle the exception thrown from the corresponding try block, preventing abnormal program termination.

finally: The finally block is used to execute cleanup code that must run regardless of whether an exception occurs or not, such as releasing system resources.

46. What is the difference between throw and throws?

throw explicitly raises an exception object at runtime, while throws declares in the method signature the exceptions that may be propagated to the caller.

throw

throw is a Java keyword used to explicitly generate and propagate an exception object from within a method or block at runtime.

Key Points

  • Transfers control immediately to the nearest matching catch block or to the caller
  • Used inside the method body
  • Followed by an exception object (instance)

throws

throws is a Java keyword used in a method signature to declare that the method may propagate one or more specified exceptions to its calling method instead of handling them internally.

Key Points

  • Used in the method declaration
  • Followed by exception class names
  • Informs the compiler and caller about possible exceptions

47. Can a finally block exist without a catch?

Yes, a finally block can be used without a catch block. In such cases, the try block is followed directly by finally. This is useful when you want to execute cleanup code (like closing resources) regardless of whether an exception is thrown or not. However, a try must always be followed by either catch or finally.

Java Keywords and Modifiers

48. What are access modifiers in Java?

Access modifiers in Java define the scope or visibility of classes, methods, and variables. They control where the members can be accessed from.

The four main access modifiers are: public, private, protected, and default (no modifier). They help enforce encapsulation and proper code structure. Keywords that define access levels: public, private, protected, and default.

49. Difference between public, private, protected, and default?

  • public: Accessible from anywhere.
  • private: Accessible only within the same class.
  • protected: Accessible within the same package and by subclasses in other packages.
  • default (no modifier): Accessible only within the same package.

50. What is the use of the static keyword?

The static keyword allows a variable or method to belong to the class rather than instances of it. It is used for memory efficiency, shared constants, or utility methods. Static methods cannot access non-static members directly. It is also used in static blocks and nested classes.

51. What is the use of the final keyword?

Prevents change (used with variables, methods, and classes). The final keyword is used to restrict changes. A final variable cannot be reassigned, a final method cannot be overridden, and a final class cannot be extended. It ensures immutability and security in certain scenarios.

52. What is the transient keyword?

Used to skip fields during serialization. The transient keyword is used to prevent a variable from being serialized. When an object is converted to a byte stream (e.g., during file saving), transient fields are skipped. It’s useful for sensitive or non-serializable data.

53. What is the volatile keyword?

Ensures changes to a variable are visible to all threads. The volatile keyword ensures visibility of changes to a variable across threads. When a variable is declared volatile, its value is always read from main memory, not from a thread’s local cache. It is used in multithreading to avoid memory inconsistency issues.

Miscellaneous

54. What is garbage collection in Java?

Garbage collection in Java is the process of automatically deleting unused objects from memory. The JVM handles this to prevent memory leaks and improve performance. Objects without any references are eligible for garbage collection. Developers can suggest garbage collection using System.gc(), but it’s not guaranteed to run immediately.

55. What are constructors and types of constructors?

Constructors are special methods used to initialize objects in Java. They have the same name as the class and no return type. Types include default constructor (no parameters), parameterized constructor, and copy constructor (user-defined). Constructors can be overloaded for flexibility.

56. can we overload constructors?

Yes, constructors can be overloaded in Java. This means creating multiple constructors with different parameter lists. It allows objects to be created in different ways. It enhances flexibility when initializing objects.

57. What is the default value of instance variables?

Depends on type: int → 0, boolean → false, Object → null.

In Java, instance variables get default values if not explicitly initialized. For example, int is 0, boolean is false, char is \u0000, and object references are null. These defaults help avoid compilation errors due to uninitialized variables.

58. What are anonymous inner classes?

Classes without a name defined within another class. Anonymous inner classes are unnamed classes defined and instantiated in a single expression. They are often used to implement interfaces or extend classes for one-time use. They are commonly used in event handling and threading. Being concise, they make code cleaner in specific scenarios.

59.What is the difference between abstract class and interface?

An abstract class can have both abstract and concrete methods, while an interface can only have abstract methods (Java 8+ allows default and static methods). A class can inherit only one abstract class but can implement multiple interfaces. Abstract classes are for shared base behavior, interfaces for capability declaration. Interfaces support multiple inheritance.

60. Can we create an object of an abstract class or interface?

No, we cannot create objects of an abstract class or interface directly. They are incomplete and meant to be extended or implemented. However, we can reference them using subclass or implementing class objects. Anonymous classes can also provide concrete implementations at runtime.

Conclusion & Next Steps

If you’re serious about landing your first Java developer role, this guide is all you need. Go through each question, understand the concepts, and practice regularly.

📌 Don’t stop here — explore more interview-specific resources on this website:

✨ Bookmark this post, share it with your friends, and revisit it before your next interview — it could be the difference between rejection and selection.

Wishing you all the best in your Java journey!