Consider the below Code snippet: class Calculator {
Consider the below Code snippet:
class Calculator {
void calculate(int a, int b) {
class Multiply {
int product() {
return a * b;
}
}
Multiply multiply = new Multiply();
System.out.println("Product: " + multiply.product());
}
}
public class Main {
public static void main(String[] args) {
Calculator calculator = new Calculator();
calculator.calculate(5, 3);
}
}
What will be the output?
Show answerHide answer
Correct answer: (A) Product: 15
Explanation
Java allows a local class inside a method, and it can use the method's effectively final parameters a and b. product() returns 5 × 3 = 15, so "Product: 15" is printed.