Menu
Topics Index
...
`

Classes inside other class and Type casting


If you need explanation Read this topic

If you need Answer Take test on this topic

Classes inside other class and Type casting
What will be the output of the following program?
public class OutputIs {
    public static void main(String[] args) {
        HelloWorld hw = new HelloWorld();
        hw.Helloworld();
        hw.HelloWorld();
        System.out.println(((int) (char) (byte) 56));
    }
}
class HelloWorld {
    public void Helloworld() {
        System.out.println(((char) (byte) 56));
    }
    public void HelloWorld() {
        System.out.println(((int) (byte) 56));
    }
}
class string {
    string() {
        System.out.println(((double) (char) (byte) 56));
    }
}

A. 8
-1
65535
B. ?
56
56
C. 8
-1
65535
65535.0
D. ?
56
56
56.0
E. Some other output
F. Compilation Error or Runtime Error
Topic: Calling A Class From Another Class In Java

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.

Ans is E. The output is
8
56
56. Helloworld will print 8 because 56 typecasted into byte would give 56 and to char will give 8 but when char 8 is type casted into int it would give 56

Posted by Nikhil Sulibhavi    2014-05-02 14:17:36


Ans:F compilation error: duplicate methods Helloword()

Posted by Indrasena Reddy    2014-05-02 14:38:22


No winner for this dose. Correct option is 'E' :(. Nikhil Sulibhavi was already won in this week.

Posted by Merit Campus    2014-05-05 04:38:24


© meritcampus 2019

All Rights Reserved.

Open In App