Author | Topic: Inner Classes... |
Saraswati unregistered |
posted April 28, 2000 02:22 PM
I was going through a book which says "Members of inner class are known only within the scope of inner class and may not be used by outer class" so,
Here are we not calling the inner method in outer class? Please correct me.... [This message has been edited by maha anna (edited April 28, 2000).]
|
satya5 ranch hand |
posted April 28, 2000 02:29 PM
"Member of inner class ...." means member variables of the inner class can The code compiles because it accesses the outer This is allowed, with some restrictions ofcourse. Regds. - satya
|
maha anna bartender |
posted April 28, 2000 04:06 PM
Saraswati, Members of a innerclass means all the (var/methods/innerclasses/innerinterfaces) inside the inner class . This statement is applicable not only to an innerclass, it can also be applicable to any type of a class. For ex. 1. normal-packagelevel-toplevelclass Having said that, in your code you are not directly accessing the innerclass member (here the method display() ). What you are doing is accessing a very valid Outer class's ( its own ) member Inner . Once you have an instance of the Innerclass then you can always access the Innerclass's members through the created ref. A class can always access its own members right?. If the owner can't access then its not fair right ? This is what happens in your code. So it compiles fine. Instead try the foll. code. This will not compile.
Satya, regds [This message has been edited by maha anna (edited April 28, 2000).]
|
satya5 ranch hand |
posted April 29, 2000 11:30 AM
Thanks for following up Maha... hmm...I got the qstn wrong! anyways... - satya
|
maha anna bartender |
posted April 29, 2000 12:17 PM
Satya, Did I upset you. First I thought I needn't make a note to you. Then I thought Satya should know what he is actually thinking of the qstn like that. . Is it ok? regds
|
satya5 ranch hand |
posted April 29, 2000 12:38 PM
Perfect that you mentioned .... Maha! NO, I am NOT upset ! see ... i am ... I am glad you mentioned. Moreover, I am answering the qstn half-hearted
- satya
|
Saraswati unregistered |
posted April 29, 2000 01:48 PM
Thanks Maha and satya.
|
satya5 ranch hand |
posted April 29, 2000 02:08 PM
As Maha said : "Members of inner class mean ....." Also, I have seen many times people suggesting the "Write some code and check it ..." Please donot get me worng. But if you follow the above BTW, the answer to your question is YES. Hope this helps. code: ps: I already had a class called Outer so I used Outer1.
|
| | |