Govt. Exams
Entrance Exams
Method overloading allows multiple methods with the same name but different parameters (number, type, or order) in the same class. This is a way to implement compile-time (static) polymorphism.
'this' is a reference variable that refers to the current object instance. It is used to distinguish instance variables from local variables with the same name, or to pass the current object as a parameter.
Lambda expressions were introduced in Java 8, enabling functional programming. Syntax: (parameters) -> expression or statement
s1 is created in string pool, s2 is a new object in heap. Though content is same, references are different, so == returns false.
== compares object references (memory addresses). equals() method compares actual content/values and can be overridden.
Java uses pass-by-value for all parameters. For objects, the value passed is the reference, but the reference itself is passed by value.
Evaluation: (true && false) || true = false || true = true. AND operator (&& has higher precedence than OR (||).
This is valid method overloading. Two methods with same name but different parameters (method signature) is allowed in Java.
Variables declared inside a method have local scope and are only accessible within that method. They are destroyed when the method returns.
Static variables are initialized only once when the class is first loaded into memory, regardless of object creation.