permaculture playing cards*
The moose likes Beginning Java and the fly likes Private Modifer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Private Modifer" Watch "Private Modifer" New topic
Author

Private Modifer

Deon Smith
Greenhorn

Joined: Mar 08, 2002
Posts: 7
The question I have of the code below is, why is Alpha a not of type Alpha but of type Beta?

Objects of type Alpha can inspect or modify the iamprivate variable and can invoke privateMethod, but objects of other types cannot. For example, the Beta class defined here:

[ Message edited to preserve formatting of code using the [code] and [/code] UBB Tags. -ds ]
[ July 21, 2002: Message edited by: Dirk Schreckmann ]
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Object "a" is an instance of class Alpha. Therefore, no instance of class Beta is able to access a private member of class Alpha.
If you want to access a private member of class Alpha, then you will have to do it from an instance of class Alpha.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by Deon Smith:
The question I have of the code below is, why is Alpha a not of type Alpha but of type Beta?

That is not the case. a is of type Alpha. Why did you believe that a were of type Beta?
I'd recommend that you carefully reread the lesson from Sun's Java Tutorial where you got this example (Controlling Access to Members of a Class).
[ July 21, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Private Modifer
 
Similar Threads
Modifiers Question
can we override private method?
novice in java,please help!
Protected and default access of a class member
accessing private member/method from a diff class.