s1 is created in string pool, s2 is a new object in heap. Though content is same, references are different, so == returns false.
Q.34Medium
Which of the following is a feature of Java 8 that allows functional programming?
Answer: A
Lambda expressions were introduced in Java 8, enabling functional programming. Syntax: (parameters) -> expression or statement
Q.35Medium
What is the purpose of the 'this' keyword in Java?
Answer: B
'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.
Q.36Medium
Which of the following correctly demonstrates method overloading?
Answer: B
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.
Q.37Medium
Which of the following statements about static methods is correct?
Answer: C
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).
Q.38Medium
What will happen if you try to access an index out of bounds in an array?
Answer: C
Accessing an array index that doesn't exist throws an ArrayIndexOutOfBoundsException at runtime. This is a checked exception that must be handled or declared.
Q.39Medium
Which access modifier allows a member to be accessible only within the same package?
Answer: D
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.
Q.40Medium
What is the difference between 'break' and 'continue' in loop statements?
Answer: B
'break' immediately exits the loop, while 'continue' skips the remaining statements in the current iteration and jumps to the next iteration.