| 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
|
 |
 |
|
|
subject: Doubt
|
|
|