• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt  RSS feed

 
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 ?
 
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.
 
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
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!