Menu
Question Index
...

What will be the output of the following program?

public class One {
    private String msg;
    void setOne(String str1) {
        msg = str1;
    }
    String getOne() {
        return msg;
    }
    public static void main(String s[]) {
        One objone = new One();
        objone.setOne("ONE");
        objone.getOne();
        Two objtwo = new Two();
        objtwo.setOne("TWO");
        objone.getOne();
    }
}
class Two extends One {
    void setOne(String str2) {
        msg = str2;
    }
}


ONE
TWO
ONETWO
(EMPTY)
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Using private Keyword In Java For Access Control

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App