Core Java Interview Questions and Answers
1) What are static blocks and static initializers in Java?
Static blocks are code inside 'static { }' that run once when the class is loaded. Static initializers
initialize static variables.
2) How to call one constructor from another constructor?
By using 'this()' inside a constructor to call another constructor of the same class.
3) What is method overriding in Java?
Overriding happens when a subclass provides a new implementation of a parent method with the
same signature.
4) What is 'super' keyword in Java?
Refers to parent class object. Used to call parent constructor or method.
5) Difference between method overloading and method overriding?
Overloading: Same method name, different parameters, same class. Overriding: Same method
signature, different class (subclass).
6) Difference between abstract class and interface?
Abstract class: Can have abstract + concrete methods, constructors allowed. Interface: Only
method declarations (till Java 7), supports default/static methods (Java 8+).
7) Why Java is platform independent?
Because Java compiles to bytecode that runs on JVM, available for all platforms.
8) What is method overloading in Java?
Having multiple methods with the same name but different parameter lists.
9) What is difference between C++ and Java?
Java: Platform-independent, automatic garbage collection, pure OOP. C++: Platform-dependent,
manual memory management, hybrid OOP.
10) What is JIT compiler?
Just-In-Time compiler converts bytecode into native machine code at runtime.
11) What is bytecode in Java?
Intermediate code (.class file) generated by compiler, executed by JVM.
12) Difference between 'this()' and 'super()' in Java?
this(): Calls another constructor in same class. super(): Calls parent constructor.
13) What is a class?
A blueprint for creating objects, defining fields and methods.
14) What is an object?
An instance of a class with state and behavior.
15) What is method in Java?
A block of code that performs a specific task, defined inside a class.
16) What is encapsulation?
Wrapping data and methods together. Achieved by private fields + getters/setters.
17) Why main() method is public, static, and void in Java?
public: JVM can access it. static: No object needed. void: Returns nothing.
18) Explain about main() method in Java?
Entry point: 'public static void main(String[] args)'. args stores command-line arguments.
19) What is constructor in Java?
Special method used to initialize objects, same name as class, no return type.
20) Difference between length and length() method in Java?
length: property for arrays. length(): method for Strings.
21) What is ASCII Code?
Character encoding standard using values 0–127.
22) What is Unicode?
Universal character encoding supporting all languages. Java uses Unicode.
23) Difference between Character Constant and String Constant in Java?
Character constant: Single char in ''. String constant: Sequence of chars in "".
24) What are constants and how to create constants in Java?
Constants are fixed values created using 'final' keyword.
25) Difference between >> and >>> operators in Java?
>>: Signed right shift (preserves sign). >>>: Unsigned right shift (fills with zeros).