• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!