Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

constructor  RSS feed

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class A
{
A()
{
}
}
The class A can be referenced outside the package in which it is defined.
The class A cannot be instantiated outside the package in which it is defined.
The class A cannot be extended outside the package in which it is defined.
The class A can be referenced, instantiated or extended anywhere.
The above code will cause a compiler error. The constructors of public class have to be public.
Can anybody tell me the correct option's?.I think 1,2,3 and 4 are correct option's, please throw some light on it.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The correct ans are 1 and 4 as a public class can be referenced, instantiated and extended anywhere. hope this helps.
Sonali
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
the correct answers are 1 and 4
 
Sheriff
Posts: 12470
205
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre>
public class A {
A() {}
}
</pre>

The class A can be referenced outside the package in which it is defined. TRUE because class A is public.
The class A cannot be instantiated outside the package in which it is defined. TRUE because constructor A() has default access (friendly/package), only classes in the same package will be able to create instances of class A
The class A cannot be extended outside the package in which it is defined. TRUE Even though class A can be referenced outside the package in which it is defined, it cannot be extended by any class outside the package because of the way the Java compiler inserts an implicit call to super() in a constructor. That implicit call to super() would fail if the class were in a different package.
The class A can be referenced, instantiated or extended anywhere.
FALSE see answers 2 & 3
The above code will cause a compiler error. The constructors of public class have to be public. FALSE all access specifiers are valid for constructors. Also, since constructors are not methods, you can even downgrade the accessibility of a constructor in a subclass, i.e. make it more restrictive than its superclass' constructor.
Junilu Lacar
(edited comments for #3...tricky)

[This message has been edited by JUNILU LACAR (edited April 28, 2001).]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!