Govt. Exams
Entrance Exams
'break' immediately exits the loop, while 'continue' skips the remaining statements in the current iteration and jumps to the next iteration.
When no access modifier is specified, it's called package-private or default access. Members with default access are accessible only within the same package, not from other packages.
Accessing an array index that doesn't exist throws an ArrayIndexOutOfBoundsException at runtime. This is a checked exception that must be handled or declared.
Static methods belong to the class, not to any instance. They are called using the class name (e.g., ClassName.methodName()). They cannot directly access instance variables and cannot be overridden (though they can be hidden).
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.