This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt" Watch "Doubt" New topic
Author

Doubt

Puja S
Ranch Hand

Joined: Jan 06, 2005
Posts: 51
Hi,

public class A
{
A()
{
}
}

1. The class A can be referenced outside the package in which it is defined.
2. The class A cannot be instantiated outside the package in which it is defined.
3. The class A cannot be extended outside the package in which it is defined.
4. The class A can be referenced, instantiated or extended anywhere.
5. The above code will cause a compiler error. The constructors of public class have to be public.


The answer is 1,2,3.......Why not 4 ?
Anand Ko
Ranch Hand

Joined: Dec 03, 2003
Posts: 79
Constructor has default access. So this class (A) can be instantiated by any other class, if the class is in the same package as that of Class A. So 1,2 & 3 are true.


Anand<br />SCJP 1.4, SCWCD 1.4, SCEA 5.0(1/3)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
PLEASE! Give your topic a meaningful title. Two topics with title "Doubt" are confusing to the other members of this forum.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Puja S
Ranch Hand

Joined: Jan 06, 2005
Posts: 51
Ok Barry and Thanks Anand for the explanation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt
 
Similar Threads
class access
constructor
Access modifiers question
class accessibility
reference of class!