posted 16 years ago
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.
{
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.
posted 16 years ago
<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).]
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).]
Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.— Junilu
[How to Ask Questions] [How to Answer Questions]

A feeble attempt to tell you about our stuff that makes us money
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
|