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

constructor

 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class A {
A(){}
}


A The class A can be referenced outside the package in which it is defined.

B The class A cannot be instantiated outside the package in which it is defined.

C The class A cannot be extended outside the package in which it is defined.

Why B & C are correct? It is a public class. Because of non-public constructor. Correct me if I am wrong.
 
christian combarel
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you're right.
If the constructor has a default acces level, you can neither instanciate the class nor extends it outside the package.
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic