Question :How the private constructor is called in the main java
programme? (CoreJava)
Answer :Have a look at this demo. public class Test2
{
private Test2()
{
System.out.println("Test2class");
}
class Subclass extends Test2
{
public Subclass()
{
System.out.println("Subclass");
}
}
public static void main(String[] args)
{
Subclass s = new Test2().new Subclass();
}
}
This works because an inner class is allowed to access private members of
its enclosing instance, including the private constructor.
www.interviewhelper.org is a hope for all the Job seekers. Users can find unlimited here. These range from technical to HR, from functional to behavioral. www.interviewhelper.org contains in the fields like Ajax,VB,Networking,Sharepoint,JEE,Perl,Javascript,Bioinformatics,Classic ASP,Unix,Linux,Accounting,Oracle DBA,Microprocessor,Bluetooth,jms,jme,.net framework,ABAP,ASP,ASP.net,Basic .net Framework,Interview Questions,C language,C++,database,Oracle,Java,PHP,LAMP,SAP etc.
Thursday, March 12, 2009
How the private constructor is called in the main java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment