- Why String is immutable in Java?
- What is static in java?
- What is final in java?
- What is this word in java?
- What is finally and where do we use it?
- What is Autoboxing and unboxing?
- What is serialization and deserialization?
- What is an abstract modifier?
- What is call by reference and call by value?
- Primitives and Non-Primitives datatypes in Java?
- String is primitive or non-primitive?
Ans : String
is a non-primitive (reference) type.
- What is the method of overloading?
- Why is it important to override HashCode() when you override equals()?
- What is the difference between a checked and unchecked exceptions?
- Difference between final, finally, finalize?
- Difference between abstract and interface?
- Difference between String Builder and String Buffer?
- Difference between Array and ArrayList?
- Difference between ArrayList and LinkedList?
- How to define dynamic array?
- Can we create the object for the abstract classes?
- Ans : No, we cannot directly create an object of an abstract class in Java. This is because an abstract class is incomplete—it may contain abstract methods that don’t have a body. Java prevents you from creating an instance of something that’s not fully defined.
- Can we create the object for an interface?
- Ans : No, you cannot directly create an object of an interface in Java. An interface is like a pure blueprint—it only defines what should be done, not how. Since there’s no actual implementation in it (at least before Java 8), there’s nothing for Java to instantiate!
- Can we create constructor of abstract class?
- Ans : Yes, absolutely! While you can’t create an object of an abstract class directly, you can define a constructor inside it—and it’s actually quite useful.
- Why define a constructor in an abstract class?
- Ans : Because when a subclass inherits the abstract class, the constructor of the abstract class is automatically called when the subclass object is created. It allows the abstract class to initialize shared variables or run setup code.
- Can constructor be overloaded. Explain why?
- Can main method be overloaded?
- Ans : Yes, the
main
method can be overloaded in Java—just like any other method!- Can main method be overridden?
- Ans : No, the
main
method cannot be overridden in the traditional sense.- 🧠Here’s why:
Overriding applies to instance methods—that is, non-static
methods that belong to objects.
But themain
method in Java isstatic
, which means it belongs to the class, not an instance of the class. Sincestatic
methods are not part of the object’s inheritance structure, they are not overridden, though they can be hidden if redefined in a subclass.- Can we override static method?
- Ans: No
- Can we overload static method?
- Ans : Yes
- Can we write non-abstract methods in Interface?
- Ans : Yes, since Java 8, interfaces can contain non-abstract methods, but only in special forms: default and static methods.
- Can we call a non-static variable in static method?
- Ans : No, a static method cannot directly access non-static variables or methods—because static methods belong to the class, while non-static members belong to an instance (object) of that class. Detail…
- Can I execute multiple catch blocks without try will it give me compile time error?
- Ans : Nope—you cannot have
catch
blocks in Java without atry
block. It’s actually a compile-time error.- How to achieve serialization and deserialization?
- If we declare the main method as private what will happen?
- Ans : If you declare the
main
method asprivate
in Java, the program will compile, but it will fail to run, throwing a runtime error.- How to check whether the array is empty and null?
- What are the classes available in a list interface?
- What is the use of constructor in java?
- What is Hashmap?
- Can we store objects in Hashmap and how to retrieve them?
- Ans : you can store objects in a
HashMap
as values, and even use objects as keys—as long as they properly implementhashCode()
andequals()
. Details- Difference between Hash Map and Hash Set?
- Where did you use HashMap in your Automation project?
- Access modifiers in java and its scope?
- What is meant by Thread?
- What is singleton class in java?
- What is the difference between static binding and dynamic binding?
- Is Hashmap thread safe?
- Ans : No, a
HashMap
is not thread-safe in Java- What is static, How to set value of static variable?
- Can we overload private methods?
- Ans : Yes, private methods can be overloaded in Java—but with a key detail: they can only be accessed and overloaded within the same class.
- Is it possible to extend Final Class?
- Ans : No, it is not possible to extend a
final
class in Java. When a class is declared asfinal
, it means that the class is not allowed to be subclassed—in other words, you cannot create a child class that inherits from it.- Is it possible to override Static method?
- Ans : No, you cannot override a static method in Java. Static methods are bound at compile time, not at runtime, which means they are associated with the class itself, not with instances of the class.
- Is it possible to overload main method?
- Ans : Yes, it is absolutely possible to overload the
main()
method in Java—just like any other method. However, there’s a twist: only the standardmain(String[] args)
method is called by the JVM when your program starts. Any other overloaded versions must be called manually from within your code.- Is it possible to initialize a variable present in an Interface?
- Ans : Yes, it is possible—but with a twist. In Java, any variable declared in an interface is implicitly
public
,static
, andfinal
, meaning it must be initialized at the time of declaration, and its value cannot be changed later.- Example :
- interface Constants {
- int MAX_USERS = 100; // implicitly public static final
- }
- What would happen, if multiple inheritance is possible, in Java?
- Explain Exceptions hierarchy in java?
- Explain Set and Map in Java?
- Explain about Inheritance.
- Difference between overloading and overriding?
- Difference Encapsulation and Abstraction ?
- Difference between throw and throws?
- What is polymorphism?
- How and when to use interface?
- Can we instantiate an interface?
- Ans : Not directly! You cannot instantiate an interface because it’s a contract, not a concrete class. Think of it like a blueprint—you can’t build with a blueprint alone; you need to create a class that uses the blueprint to build something.
- Can we over load main method in Java?
- Ans : Absolutely, we can overload the
main
method in Java.- Can we override constructor?
- Where do you use polymorphism in java?
- Why do we use finally and how it differs from the final keyword?
- Can we use multiple catches? When can we use multiple catches?
- How to prevent the override method in Java?
- Ans : To prevent a method from being overridden by subclasses, you simply mark the method with the
final
keyword. If a subclass attempts to override afinal
method, the compiler will throw a compile-time error:- Why is the main method static?
- What is the use of static variables?
- What is the difference between list and set?
- How will you access default and protected class?
- Why Object creation not possible in Abstract classes?
- Situations when we use abstraction and Interface?
- Explanation about loosely coupled and tightly coupled?
- Will Java provide default constructor by own ? How
- Difference between Arraylist and Linked List,In which situation they are used ?
- Difference between List list = new ArrayList() and ArrayList list = new ArrayList();
- In which situation the method should be static and when non static?
- How does HashMap is implemented using key value pair?
- If there is a class and an abstract class, and the class contains a user-defined constructor along with a main method, which one will be executed first during program execution?
- Ans : The main method executes first, as it’s the program’s entry point, and then the user-defined constructor runs when the class is instantiated.
- What do you mean by POJO why we use POJO?