Menu
Topics Index
...
`

Horse says hello


If you need explanation Read this topic

If you need Answer Take test on this topic

Horse says hello
What will be the output of the following program?
public class Enter {
    public static void main(String[] args) {
        class Horse {
            public String name;
            public Horse(String s) {
                name = s;
            }
        }
        Object obj = new Horse("Hai hello good day");
        Horse h = (Horse) obj;
        System.out.println(h.name);
    }
}

A. Hai hello good day
B. (No output)
C. null
D. Compilation Error
E. Runtime Error
Topic: Advanced Java Programming Concepts

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.

option A, Because Object class is base class in java.

Posted by Yashasvi Bandi    2014-04-16 04:13:00


Ans is A since obj is object to object class which is base class in Horse class we created a Horse constructor in which we passed a string s and s is assigned to name and h is object to Horse class and prints the string which is passed as "Hai hello good day"

Posted by Naga Sinst    2014-04-16 15:59:36


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

Posted by Merit Campus    2014-04-17 04:28:08


© meritcampus 2019

All Rights Reserved.

Open In App