Menu
Topics Index
...
`

Object for class


If you need explanation Read this topic

If you need Answer Take test on this topic

Object for class
What will be the output of the following program?
class Dog {
    public static void bark() {
        System.out.print("Bow ");
    }
}
class Cat extends Dog {
    public static void bark() {
    }
}
public class Fight {
    public static void main(String args[]) {
        Dog do = new Dog();
        Dog ca = new Cat();
        Dog.bark();
        ca.bark();
    }
}

A. Bow Bow
B. Bow Bow Bow
C. Bow Bow Bow Bow
D. Some other output
E. Compilation Error or Runtime Error
Topic: Static and Non Static Variables - Static and Non Static Methods

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

B.

Posted by Rajashekar Chelpuri    2013-12-12 03:26:28


Ans is E.. do is keyword in java.. so it leads to compilation error..

Posted by Om Prakash Om    2013-12-12 04:10:14


answer is E,do cannot be used as identifier,as do keyword is used  in Do-While loop

Posted by Praveen Kumar    2013-12-12 04:39:26


it generates error because in main method do is keyword and also static methods cannot be accessed using class objects..hence answer is E

Posted by Sangeetha Ptl    2013-12-12 15:14:19


Congratulations Om Prakash Om. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2013-12-13 03:57:46


© meritcampus 2019

All Rights Reserved.

Open In App