Menu
Topics Index
...
`

Can not be accessed


If you need explanation Read this topic

If you need Answer Take test on this topic

Can not be accessed
At what lines will there be compilation errors?
class Secret {
    private void getSecret() {
    }
    void getSecret(int i) {
        getSecret();/* LINE X */
    }
    protected void getTopSecret(String s) { /* LINE Y */
    }
}
class TopSecret extends Secret {
    void getSecret() {
        super.getSecret(); /* LINE A */
    }
    public void getSecret(int i) {
        getSecret(); /* LINE B */
        super.getSecret(i); /* LINE C */
    }
    private void getTopSecret(String s) { /* LINE D */
    }
}

A. X, A, D
B. X, Y, A, B, C, D
C. A, D
D. X, B, C
Topic: Unknown

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.

And is c..we cant acces privte method n and we cant hav 2 methods with Sam name..getTopScrt(string) method

Posted by Uday Kumar    2014-06-23 08:58:13


answer is c....we cant acces the private methods using super..nd we cant reduce the restriction like frm protectd to private

Posted by Vijay Kumar    2014-06-23 09:33:36


i guess ANS. is c
Explanation:
------AT line A getSecret() is called which is private n as per rule private method's scope is restricted to the class in which it is declared.
------AT line D there error will come like " attempting to assign weaker access privileges" because if we want to override method which is protected we should use the access specifier either "friendly" or "public".

Posted by Mânïshå Mùlchåndânï    2014-06-23 09:36:53


Answer is C.Because getSecret cannot be accessed outside the Secret Class

Posted by Jagadeswari Gandham    2014-06-23 10:51:14


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

Posted by Merit Campus    2014-06-24 04:03:05


© meritcampus 2019

All Rights Reserved.

Open In App