class Dog { public static void bark() { System.out.print("woof "); }}class Alsation extends Dog { public static void bark() { }}public class Bark { public static void main(String args[]) { Dog woofer = new Dog(); Dog nipper = new Alsation(); woofer.bark(); nipper.bark(); }}What is the output

  1. woof

  2. woof woof

  3. Nothing will be printed as output

  4. None of the above


Correct Option: B

AI Explanation

To answer this question, we need to understand the concept of method overriding in Java.

In the given code, there are two classes: Dog and Alsation. The Dog class has a static method called bark() that prints "woof ". The Alsation class extends the Dog class and also has a static method called bark(). However, the Alsation class does not provide an implementation for the bark() method.

In the Bark class's main() method, two objects are created: woofer of type Dog and nipper of type Alsation. When the bark() method is called on woofer, it will call the bark() method of the Dog class, which prints "woof ". When the bark() method is called on nipper, it will call the bark() method of the Alsation class. Since there is no implementation of the bark() method in the Alsation class, it will use the implementation of the bark() method from the superclass (i.e., Dog class).

Therefore, the output will be "woof woof ".

Option B) woof woof - This option is correct because it matches the output explained above.

The correct answer is B) woof woof.

Find more quizzes: