Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt

 
Puja S
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PLEASE! Give your topic a meaningful title. Two topics with title "Doubt" are confusing to the other members of this forum.
 
Puja S
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Barry and Thanks Anand for the explanation
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic