Menu
Question Index
...

What will be the output of the following program? Assume that all the below classes are in the same package.

public class Rust {
    public static void main(String[] args) {
        new R().m2();
        new U().m1();
        new S().m1();
        new T().m1();
    }
}

class R {
    private void m1() {
        System.out.print("R");
    }
    public void m2() {
        m1();
    }
}

class U {
    protected void m1() {
        System.out.print("U");
    }
    public void m2() {
        m1();
        new R().m2();
    }
}

class S {
    public void m1() {
        System.out.print("S");
        new U().m1();
    }
}

class T {
    void m1() {
        System.out.print("T");
    }
}


RUSUT
RSUTU
RUST
Compilation error in the method m2 of class R
Compilation error for some other reason

Doubts

Problems

Topic: Access Modifiers In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App