Question Index

Compare the following programs?

public class Scroll {
    public static void main(String[] args) {
        Scroll t = (Scroll) new Object();
class Scroll2 {
    public static void main(String[] args) {
        String s = null;
        System.out.println(s instanceof String);

Both Scroll and Scroll2 produce same output.
Scroll and Scroll2 produce different output.
Scroll compiles and runs with out any error, but Scroll2 gives compilation error.
Scroll2 compiles and runs with out any error, but Scroll gives compilation error.
Both Scroll and Scroll2 fail to execute.



Topic: Assigning Super Class Reference To A Sub Class Reference In Java

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App