adplus-dvertising
frame-decoration

Question

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.

Posted under Java Programming

Answer: (c).Compilation fails.

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What will be the output of the program?

Similar Questions

Discover Related MCQs

Q. Which three statements are true?

1. The default constructor initialises method variables.
2. The default constructor has the same access as its class.
3. The default constructor invokes the no-arg constructor of the superclass.
4. If a class lacks a no-arg constructor, the compiler always creates a default constructor.
5. The compiler creates a default constructor only when there are no other constructors for the class.

Q. What is the numerical range of char?

Q. Which of the following are Java reserved words?

1. run
2. import
3. default
4. implement

Q. Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?

Q. Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?

Q. Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

Q. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?

Q. Which interface does java.util.Hashtable implement?

Q. Which interface provides the capability to store objects using a key-value pair?

Q. Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?

Q. Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization?

Q. Which is valid declaration of a float?

Q. Which of the following are true statements?

1. The Iterator interface declares only three methods: hasNext, next and remove.
2. The ListIterator interface extends both the List and Iterator interfaces.
3. The ListIterator interface provides forward and backward iteration capabilities.
4. The ListIterator interface provides the ability to modify the List during iteration.
5.The ListIterator interface provides the ability to determine its position in the List.

Q. Which statement is true for the class java.util.ArrayList?

Q. Which statement is true for the class java.util.HashSet?

Q. Which of the following statements about the hashcode() method are incorrect?

1. The value returned by hashcode() is used in some collection classes to help locate objects.
2. The hashcode() method is required to return a positive int value.
3. The hashcode() method in the String class is the one inherited from Object.
4. Two new empty String objects will produce identical hashcodes.

Q. What two statements are true about properly overridden hashCode() and equals() methods?

1. hashCode() doesn't have to be overridden if equals() is.
2. equals() doesn't have to be overridden if hashCode() is.
3. hashCode() can always return the same value, regardless of the object that invoked it.
4. equals() can be true even if it's comparing different objects.

Q. Which two statements are true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden?

1. If the equals() method returns true, the hashCode() comparison == must return true.
2. If the equals() method returns false, the hashCode() comparison != must return true.
3. If the hashCode() comparison == returns true, the equals() method must return true.
4.If the hashCode() comparison == returns true, the equals() method might return true.

Q. Which of the following is smallest integer data type ?

Q. Which of the following is not a primitive data type ?