Entry
Java: Class: Friend: Can someone tell me what friend class is in Java?
Sep 7th, 2009 04:50
Knud van Eeden, Joe Bloggs,
----------------------------------------------------------------------
--- Knud van Eeden --- 30 April 2002 - 08:40 pm ----------------------
Java: Class: Friend: Can someone tell me what friend class is in Java?
---
Put that classes in the same package.
---
The equivalent of 'friend' in Java is the 'package'.
---
The Java package mechanism provides the power of 'friend' classes, with
much better control.
---
A package is simply a group of classes (e.g. one or more classes stored
in e.g. one and the same file, or several files). You can use that
files
with classes in your program by using the keyword 'import'.
---
A class can designate any of its member variables and member functions
as available only to other classes in the same package.
---
So Java has four levels of specifying access to class members:
1. private:
Available only to this class (Same as C++).
2. protected:
Available to derived classes and other classes in the same package.
3. Package:
Available to other classes in the same package
(This is the default access specifier - there is no 'package'
keyword).
4. public:
Available to everybody (Same as C++).
---
The big advantage of Java packages over C++ friend classes is that it
is not an all-or-nothing affair.
---
You can still declare private member variables which can not be seen
outside a class.
---
[Internet: source: http://www.google.com: search for 'How can you make
a function a friend of a class in Java ?':
http://www.firststep.com.au/jlc/javacc/keywords.html]
---
---
Internet: see also:
C#: Class: Friend: Can someone tell me what a friend class is in C#?
http://www.faqts.com/knowledge_base/view.phtml/aid/24737/fid/791
C++: Class: Friend: Can someone tell me what a friend class is in C++?
http://www.faqts.com/knowledge_base/view.phtml/aid/16164/fid/163
Delphi: Class: Friend: Can someone tell me what friend class is in
Object Pascal?
http://www.faqts.com/knowledge_base/view.phtml/aid/16168/fid/175
----------------------------------------------------------------------