QSpiders|JSpiders|PySpiders, NOIDA
B-4, Block-B, Sector-3, Noida
Core Java Interview Questions by Shambhu Sir
Thursday, 29 January 2026 @kumarsam07
@javac_java
➢ Basic Concept:
1. What is programming language?
2. What are the different types of programming language?
3. Explain high level programming language?
4. High level language is of how many types?
5. Explain difference between procedure oriented and object-oriented
programming?
6. Explain difference between compiler and interpreter.
7. What are the four pillars of object-oriented programming?
8. Define all four pillars such as Encapsulation, Inheritance, Polymorphism and
Abstraction.
9. How java is a platform independent language?
10. What is Byte Code/magical code in java?
11. Explain the working of JVM?
12. What are the types of Error?
13. Explain compile time error and Run time Error.
14. Explain what is exception?
15. What is exception handling?
➢ Structure of Java Program:
16. What will happen if a java program doesn’t have main method?
17. What are keywords? Mention few of them.
18. How many keywords are used in main method of java?
19. What are identifiers? Tell me all its rules.
20. What is difference between keywords and identifiers?
21. Why String[] args is used in main method of java? What is its use?
22. Explain command line argument feature.
23. What will happen if a program has multiple methods?
24. What will happen if there are multiple main method inside a program with
different arguments?
QSpiders| JSpiders Shambhu Kumar
➢ Data Types:
25. Explain data types. Why it is used?
26. How many data types are in java? Explain them.
27. Mention at least 5 differences between primitive and non-primitive data.
28. Represent byte a=100; in memory representation of 2’s compliment.
29. Represent byte a=80; in memory representation of 2’s compliment.
30. Represent byte a=-120; in memory representation of 2’s compliment.
31. Represent byte a=-28; in memory representation of 2’s compliment.
32. Design a non-primitive data for Employ with some attributes and show how to use
it.
33. Design a non-primitive data for Product with some attributes and show how to
use it.
34. Design a non-primitive data for Vehicle with some attributes and show how to use
it.
35. Design a non-primitive data for Fruit with some attributes and show how to use it.
36. Design a non-primitive data for Order with some attributes and show how to use
it.
37. Design a non-primitive data for Laptop with some attributes and show how to use
it.
38. Design a non-primitive data for Student with some attributes and show how to
use it.
39. Design a non-primitive data for Chrome with some attributes and show how to
use it.
40. Why java is called strictly typed programming language.
➢ Variable:
41. What is a variable? Why it is used?
42. What are different types of variables?
43. Explain local, static and non-static variables? How it is accessed in java program?
44. What is default value of a local variable?
45. What is scope of a local variable?
46. What is scope of a static variable?
47. What is scope of a non-static variable?
48. Can we have default value for a static or non-static variable?
49. Can we have a local variable and global (static or non-static) variable with the
same name? if so, then which variable gets preference?
50. Explain what is variable shadowing?
QSpiders| JSpiders Shambhu Kumar
➢ Primitive Type casting:
51. What is primitive type casting?
52. Explain widening and narrowing?
53. Explain implicit and explicit conversion.
54. Why widening is called implicit conversion and narrowing is called explicit
conversion?
Methods:
55. What is method? Why it is used?
56. How many methods can be designed inside a class?
57. How method is executed?
58. In which memory area method execution takes place?
59. Which mechanism is followed in method execution?
60. How we can call and execute a static type method?
61. How we can call and execute a non-static type method?
62. What is the main advantage of a method?
➔Code Reusability
63. Why main method of java should be always declared as public?
64. Why main method should be always declared as static?
65. What will happen if multiple copy of main method is loaded in memory?
//uniformity/consistency in program execution will not be maintained
66. Why main method return type is always void?
67. What is public in method?
68. Explain access modifiers?
69. How many access modifiers can be used by a method?
➔only one
70. What is static in method?
71. Explain non-access modifiers?
72. How many non-access modifiers can be used by a method?
73. What is method signature?
74. What is method declaration?
75. What is method definition?
76. What is formal argument and actual argument?
77. What is Compile Time Binding/ Early Binding?
78. What is the purpose of String[] args in main method?
➔To support Command Line Argument Feature in java
QSpiders| JSpiders Shambhu Kumar
79. If there are multiple methods inside a class along with main method then which
method will be executed?
80. If there are multiple methods inside a class without main method then which
method will be executed?
81. If there are multiple main methods inside a class with main(String[] args),
main(String args) and main(int args) method then which method will be
executed?
82. If there are multiple main methods inside a class with main(String args), main(int
args) and main(int[] args) method then which method will be executed?
83. What are the types of methods?
84. Which method can be used to transfer values from one method frame to another
method frame?
85. What value is returned from a method with return type void?
86. How many values can we return from a method?
87. Which type of method can be directly called inside [Link]()?
88. Can we use static and abstract keyword together?
➔No, it forms illegal combination
89. Explain what is call by value?
90. Explain what is call by reference?
91. Does java support call by reference?
➢ JVM, JRE, JDK, JIT Compiler:
[Link] JVM and its working.
[Link] JRE.
[Link] JDK.
[Link] JIT Compiler.
[Link] the difference between JVM, JRE and JDK.
➢ Garbage Collection:
[Link] is Garbage Collection in Java?
➔Automatic process by JVM to free memory by destroying
unwanted members (such as unreachable objects, local variables
etc)
QSpiders| JSpiders Shambhu Kumar
[Link] is Garbage Collection needed?
➔Prevents memory leaks and “OutOfMemoryError” by
reclaiming memory from unused objects.
[Link] does Java Garbage Collector identify unused objects?
➔Using Reachability Analysis
100. Can you force garbage collection in Java?
➔You can request it using [Link](), but it’s not guaranteed.
It is just a request to JVM to start garbage collection immediately
but JVM can ignore it.
101. Explain the working of garbage collector in java?
➔The Garbage Collector (GC) in Java is an automatic process managed
by the Java Virtual Machine (JVM) that reclaims memory by removing
objects that are no longer in use.
102. What do you mean by automatic garbage collection in java?
➔ Automatic Garbage Collection in Java means that the Java Virtual
Machine (JVM) takes care of memory management by automatically
identifying and removing unused objects (garbage) from the heap,
without requiring the programmer to explicitly delete them.
103. How Is an Object Deleted in Java?
➔In Java, objects are not explicitly deleted by the programmer like in
C/C++ (no delete keyword). Instead, object deletion is handled
automatically by the Garbage Collector (GC).
QSpiders| JSpiders Shambhu Kumar
Once there are no references to the object, Object becomes
unreachable and it becomes eligible for garbage collection.
a)
Student s = new Student(); // Object created in heap memory
S=null; // Now the Student object is unreachable
b)
Student s1 = new Student();
Student s2 = new Student();
s1 = s2; // The original object referenced by s1 is now unreachable and
s1 object will be eligible for garbage collection
c)
when stack frame is deleted then all objects of that frame will become
unreachable and it will be deleted by garbage collector.
104. What are the advantages of garbage collector?
➔ Advantages of Garbage Collector in Java
1. Automatic Memory Management
✓ Developers don’t need to explicitly manage memory
2. Avoids Memory Leaks
✓ GC cleans unreachable objects automatically.
✓ Prevents common memory leaks caused by forgetting to
deallocate memory.
3. Increased Developer Productivity
✓ Developers can focus on business logic instead of
memory management.
✓ Less boilerplate code → faster development.
4. Safety and Security
✓ Makes Java more secure and robust than manual
memory management.
5. Optimized Memory Usage
QSpiders| JSpiders Shambhu Kumar
✓ GC algorithms optimize memory which helps maintain
long-running applications with large heaps.
105. What are the disadvantages of garbage collector?
➔While the Garbage Collector (GC) makes Java memory
management easier and safer, it comes with some disadvantages as
well:
1. Unpredictable Performance (GC Pauses)
• The GC may stop application threads to reclaim memory.
• These pauses can affect performance, especially in real-time
or latency-sensitive applications.
Example: In a high-frequency trading app, even a small
pause can cause loss of money.
2. Less Control Over Memory
• In languages like C/C++, developers manually allocate and
deallocate memory.
• In Java, the GC decides when and what to clean — developers
can’t force it to run.
Calling [Link]() is just a suggestion; the JVM may ignore it.
3. Overhead and CPU Usage
• GC consumes CPU cycles to monitor, trace, and clean memory.
• In large applications, this can result in increased CPU load.
4. Memory Overhead
• Some GC algorithms may use extra memory to manage regions,
generations, or threads.
• More metadata and thread stacks → more memory consumed.
➢ OOP Programming:
QSpiders| JSpiders Shambhu Kumar
106. What is Object Oriented programming? Why it is used?
107. What are the four pillars of OOP?
108. Is java a 100% object-oriented language? Explain.
109. What is class and object? Define it.
110. What are the properties of a class?
111. Explain new keyword.
112. Explain how object is created in java?
113. What is the work of constructor?
114. What are reference data type? What is its default value?
115. Explain reference variable? What is its default value?
116. What do you mean by instantiation?
117. What is instance?
118. Explain static type members?
119. What is the main purpose of static members?
➔memory management because only one copy is loaded inside memory for
static type members
120. How many copies of static members are loaded in a program execution?
121. Why main method is always static?
122. Explain non-static members?
123. What is the main purpose of non-static members?
➔To load different copy for different object
124. How many copies of non-static members are loaded in a program execution?
125. What are class members?
126. What are instance members?
127. A static type member belongs to what?
It belongs to class
128. A non-static type members belongs to what?
It belongs to object
129. Why static members are called class members?
130. Why non-static members are called instance members?
131. What is the different memory block are created by JVM at run time. Explain
them.
132. Explain the difference between Stack and Heap Area?
133. Explain static and non-static block or what is static or non-static initializer
block?
134. Can we run a java program without main method?
135. Which type members can be accessed directly inside a static method?
136. Which type members can be accessed directly inside a non-static method?
137. Can we access a static member directly inside static block?
138. Can we access a non-static member directly inside non-static block?
139. Can we access a static member directly inside non-static block?
140. Can we access a non-static member directly inside a static block?
141. Explain variable shadowing?
142. How variable shadowing is resolved in case of static variables?
143. How variable shadowing is resolved in case of non-static variables?
QSpiders| JSpiders Shambhu Kumar
144. Explain this keyword?
145. What will be inside this keyword? OR, what does this keyword contain?
//It contains the reference of the current object under execution
146. Design a program for Object Counter.
147. Explain accessor and mutator method.
Constructor:
148. What is constructor? What is its use?
149. Explain the difference between method and constructor?
OR, how does a constructor differ from a method?
150. What is the return type of a constructor?
151. Can a constructor be static or final?
152. What are the different types of constructors?
153. Explain default constructor with its use?
154. Explain parameterized constructor? What is its use?
155. How a constructor is called?
156. Explain constructor overloading with its use?
157. What is the advantage of constructor overloading?
158. What is disadvantage of constructor overloading?
159. Explain “Boilerplate code”.
➔A set of code which is repeatedly being used with little or no
change
160. Explain constructor chaining with its use?
161. What is the advantage of constructor chaining?
//It helps to reduce boilerplate code
162. Explain this() statement.
163. How many constructors can be called by one constructor?
164. Can we make this() as the second statement?
165. Can a constructor call a method?
➔Yes
166. Can we use this() call inside a method?
➔NO
167. What are the restrictions on constructors?
168. Explain copy constructor with a program. What is its use?
QSpiders| JSpiders Shambhu Kumar
Encapsulation:
169. What is encapsulation?
170. What is data binding?
171. How we can achieve encapsulation?
172. Explain setters() and getters() method.
173. What is mutator and accessor method?
174. What is data hiding?
175. If we have to design a class and we need to set the details only
after validation, then which concept we should use?
176. Design one program to demonstrate encapsulation.
177. What are the advantages of Encapsulation?
178. What are the disadvantages of Encapsulation?
➔It leads to Boiler Plate code
179. What is a POJO (Plain Old Java Object)?
A POJO (Plain Old Java Object) is a simple, lightweight Java class that:
• Does not depend on any specific framework, technology, or external
restrictions (like EJB, JPA, Spring).
• Primarily holds data and may have simple behavior (getters, setters,
toString, etc.).
• Is not bound by special naming conventions, annotations, or inheritance
rules.
It’s basically a normal Java object used to represent data in a clean,
reusable, and flexible way.
Key Characteristics of a POJO
A POJO:
• Does not extend or implement any framework-specific class or interface.
• Uses private fields for encapsulation.
• Provides public getters and setters to access or modify data.
• May contain constructors, toString(), equals(), and hashCode().
• Has no heavy annotations or business logic.
QSpiders| JSpiders Shambhu Kumar
In Short:
A POJO is just a plain, simple Java class with private fields, public
getters/setters, constructors, and no special framework dependencies, used
mainly for holding and transferring data.
180. What is a Java Bean class? How is it different from a POJO? What
are its advantages?
A Java Bean is a special type of POJO that follows specific conventions defined by
the JavaBeans specification.
JavaBeans are commonly used for encapsulation, data transfer, and working
with frameworks (like JSP, Spring, Hibernate, etc.) that rely on this standardized
structure.
Rules for a Java Bean Class
A class is considered a Java Bean if it follows these rules:
1. Private Fields: All instance variables must be private.
2. Public Getters and Setters: To access and modify fields.
3. Public No-Arg Constructor: Allows easy instantiation.
4. Serializable (Optional but Recommended): Should implement
Serializable for object persistence and transfer across networks or files.
➢ Inheritance:
181. What is inheritance? How it is achieved in java?
182. What are the different types of inheritance?
183. Explain hierarchical inheritance.
184. Explain super keyword.
185. Explain the difference between this and super keyword.
this keyword super keyword
1. It is used to refer the non-static 1. It is used to refer the non-static
members of the same class. members of the immediate parent
class.
2. It holds the reference of current 2. It doesn’t hold any object reference.
object under execution.
QSpiders| JSpiders Shambhu Kumar
186. Explain super() statement.
187. Explain the difference between this() and super () statement.
this() super ()
1. It is used to call the constructor of 1. It is used to call the constructor of
the same class. immediate parent class.
2. It helps to achieve constructor 2. It helps to achieve constructor
chaining inside same class. chaining from child class to parent
class.
188. Can we use this() and super() together inside same constructor?
189. Can we use multiple super() statement inside a constructor?
190. How parent and child relationship is created internally?
191. Explain implicit and explicit super() statement?
192. Explain multiple inheritance?
193. Why multiple inheritance is not supported in java with class?
➔It is not supported because it creates ambiguity problem at the time of super()
194. Explain “Diamond Shape Problem”? How it is resolved in java?
➔When a class has multiple parents then it creates ambiguity problem which is
called Diamond Shape Problem. It is resolved by using interface.
195. Which type of members are not inherited from parent class to child class?
196. Can a child class inherit constructors of parent class? Why?
197. Which class is the super most parent class of every class in java?
198. Explain the difference between HAS-A and IS-A relationship.
199. Why we should favour “HAS-A” over “IS-A”?
200. Explain sealed class and its use.
➢ Upcasting/ Downcasting:
200. What is non-primitive type casting in Java?
201. What is upcasting? Give an example.
202. Is upcasting implicit or explicit in Java?
203. What is downcasting? Give an example.
204. Is downcasting implicit or explicit?
205. Explain generalization and specialization.
206. What is the difference between upcasting and downcasting?
207. Can we type cast any class to any other class in Java? Explain.
208. What members are accessible after upcasting?
209. What members are accessible after downcasting?
210. What are the risks of downcasting in Java?
211. What is “ClassCastException” and when does it occur?
212. How can you safely perform downcasting in Java?
QSpiders| JSpiders Shambhu Kumar
➔By making sure that there is parent child relationship and by using instance
of keyword
213. Give a real-world example where both upcasting and downcasting are used.
214. Write a Java program demonstrating both upcasting and downcasting.
215. In which situations would you use type casting in real projects?
➢ Polymorphism:
198. What is polymorphism?
199. Explain different types of polymorphism.
200. What is compile time and run time polymorphism? How it is
achieved in java?
201. Explain method overloading with programming examples.
202. What is advantage of method overloading?
203. Can we overload both static and non-static methods?
➔Yes
204. Can we overload main method of java?
➔Yes
205. If we have multiple main methods with different arguments then
which main method will get executed by JVM?
206. If there are multiple main methods inside a class with
main(String[] args), main(String args) and main(int args) method
then which main() method will be executed?
207. If there are multiple main methods inside a class with
main(String args), main(int args) and main(int[] args), method then
which method will be executed?
208. Why operator overloading is not allowed in java?
209. Explain method overriding with programming examples.
210. Explain all the conditions for method overriding.
211. Explain what is covariant return type in java?
212. Explain Factory Method with an example.
213. What is advantage of method overriding?
QSpiders| JSpiders Shambhu Kumar
//We can achieve/update new features from child class by changing
//old implementations of parent class at run time
214. Can we override main method?
➔No
215. Can we override static method?
➔NO
216. Why we can’t override static method?
➔static method belongs to class but overriding is allowed only for
non-static methods which belongs to object
217. Mention all the differences between method Overloading and
method Overriding.
218. Mention all the differences between Compile Time
Polymorphism and Run time Polymorphism.
219. Explain static method dispatch (Overloading) and dynamic method
dispatch (Overriding).
220. Explain variable shadowing.
221. Explain variable hiding.
222. How to Overcome variable shadowing.
➔Using this keyword
223. How to Overcome variable hiding.
➔Using super keyword or through non-primitive type casting
224. Explain method shadowing/ method Hiding.
225. Can we overload constructor?
226. Can we override constructor? why?
➔No because we can’t have constructors with the same name
inside parent and child class
227. Give some examples of method overloading?
➔print() and println() are the examples of overloaded methods
inside PrintStream class of java
228. Give some examples of method overriding?
➔toString(), equals(), hashCode(), finalize() of Object class are the
examples of Overridden methods
QSpiders| JSpiders Shambhu Kumar