What will be the output of the following Java code?
class A
{
final public int calculate(int a, int b) { return 1; }
}
class B extends A
{
public int calculate(int a, int b) { return 2; }
}
public class output
{
public static void main(String args[])
{
B object = new B();
System.out.print("b is " + b.calculate(0, 1));
}
}
class A
{
final public int calculate(int a, int b) { return 1; }
}
class B extends A
{
public int calculate(int a, int b) { return 2; }
}
public class output
{
public static void main(String args[])
{
B object = new B();
System.out.print("b is " + b.calculate(0, 1));
}
}
A. b is : 2
B. b is : 1
C. Compilation Error
D. An exception is thrown at runtime
Answer: Option C
Related Questions on Data Types and Variables
What is the maximum value that can be stored in a byte variable in Java?
A. 127
B. 255
C. 32767
D. 64
What is the default value of an int variable in Java if it's not explicitly initialized?
A. 0
B. 1
C. -1
D. Null
Which of the following is not a valid identifier for a Java variable?
A. my_var
B. _myVar
C. 3rdVar
D. $var
Join The Discussion