Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Originally posted by Srinivasa Raghavan:
Ans : A B C
A : Since the class is public
...
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
since the class is public and the access modifier for the const is not given it will take the class modifier which is "public".
Originally posted by Animesh Shrivastava:
...if u explicitly define a constructor the access sprecifiers what u specify will be its specifier. If u have not given any specifier it will be taken as the default. But remember the implicit default constructor is always public.
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
With Regards,<br />Ajay
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Tony Morris
Java Q&A (FAQ, Trivia)
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Originally posted by Animesh Shrivastava:
But remember the implicit default constructor is always public.
Originally posted by Srinivasa Raghavan:
So what is teh final answer for that question.
Constructors can't be inherited...so, wait, if we try to extend the public class Bofa outside its package, and its constructor is not inherited, then isn't that like the extended Bofa not having a constructor at all, and thus a default constructor having public access should be given to the new, extended class?
implicitly default constructor is not always public , it takes access specifier of class .
Originally posted by Parameswaran Thangavel:
hi Knecht
can i say that to extend and instantiate the class outside its package the class should have its constructor public
to have the reference outside its package its enough to have the public class (don't need worry about the constructor it can be private)
Originally posted by Pete Knecht:
(A) But since it's public, we should be able to refer to it from another package (if it's already compiled there and thus constructed, then its private constructor won't even come into play in this case, right?)
(B) Actually, I'm glad I stumbled onto this post.
Subtle variation and problem:
Take Bofa the way it is now, and add an overloaded constructor, say,
public Bofa(String s){}
Note the public access. Now can we extend and instantiate Bofa outside of its package, *if we use the overloaded constructor*? Say, with,
package other-than-Bofas;
import package-that-contains-Bofa;
class TestBofa
{ public static void main(String[] args)
{ Bofa b = new Bofa("Some String"); }
}
I'm going to guess and say yes, this will compile, but I don't know......
Originally posted by Animesh Shrivastava:
The main intention of having such kinda desgin is that no class, outside the package in which the class resides, should be able to create the object of such a class, here this kind of class is Bofa. But u can still inherit the class's members and invoke them from ur subclass.
Originally posted by Animesh Shrivastava:
Pete,
U r right, i was wrong in pointing that out.
But if suppose u have static methods out there, then i hope thats like saying
U cannot extend the class nor instantiate from outside the package but u can call static methods on it, right? like Math Class ( but its having final modifier)
Originally posted by Shivakanth Thyagarajan:
Hi Pete,
thanks for this extended reply, Please give an valid reason why Answer A is correct. I am unable to grasp it. The reason being the class Bofa cannot be extended or instantiated outside it's current package. Now if we reference it outside the package what values that reference could hold. Will that reference will serve any purpose.
Thanks
Shiva
Originally posted by Parameswaran Thangavel:
hi Knecht
i putting in different words now
instantiating the class
1) outside package
--the constructor must be public
2)within the same package
--constructor can be protected or default or public
to reference the class
1)outside package
--the class must be public (no need to care about the constructor)
2)within the same package
--the class can be public or default access
please reply me
A timing clock, fuse wire, high explosives and a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|