Menu
Topics Index
...
`

Classes inside other class1967


If you need explanation Read this topic

If you need Answer Take test on this topic

Classes inside other class1967
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;
    }
}

A. ONE
B. TWO
C. ONETWO
D. (EMPTY)
E. Some other output
F. Compilation Error or Runtime Error
Topic: Using private Keyword In Java For Access Control

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.

Access specifier of Variable msg belonging to class One is "private" so it cannot be inherited by it's subclass Two..
Variable msg is being accessed in overridden method "setOne" of class Two
Answer : F

Posted by Kittu Manoj    2014-05-15 12:43:13


ans : f
int two class msg not declared ...so can't use it in

Posted by Maheshwari Natarajan    2014-05-15 12:43:54


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

Posted by Merit Campus    2014-05-16 04:25:52


Thank you :)

Posted by Kittu Manoj    2014-05-16 04:50:20


© meritcampus 2019

All Rights Reserved.

Open In App