30/09/2018, 16:16

Poll: Kiểm tra kiến thức Core Java - 1.01

Let’s have a discussion about this problem and get the answer here http://www.indiabix.com/online-test/java-programming-test/61

  1. What will be the output of the program?


class A 
{
    final public int GetResult(int a, int b) { return 0; } 
} 
class B extends A 
{ 
    public int GetResult(int a, int b) {return 1; } 
} 
public class Test 
{
    public static void main(String args[]) 
    { 
        B b = new B(); 
        System.out.println("x = " + b.GetResult(0, 1));  
    } 
}
  • A. x = 0
  • B. x = 1
  • C. Compilation fails.
  • D. An exception is thrown at runtime.
Đỗ Trung Quân viết 18:23 ngày 30/09/2018

Answer:[spoiler] Finallllllllllllllllllllllllllllllllllllll
class A is final and so cannot be overridden.[/spoiler]

Bài liên quan
0