File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can we have public inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can we have public inner class" Watch "can we have public inner class" New topic
Author

can we have public inner class

mukki pandey
Ranch Hand

Joined: Sep 22, 2008
Posts: 58
public class TestClass {
public class A {
public void m() { }
}
class B extends A {
}
public static void main(String args[]) {
new TestClass().new A() { public void m() { } };
}
}

this code compiles fine???but we have two public class A which is inside public class testClass ...is this okie
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9319
    
  17

Yes you can have a public inner class inside a public class. The code will compile and run fine...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Arijit Daripa
Ranch Hand

Joined: Aug 09, 2008
Posts: 142
Originally posted by mukki pandey:
public class TestClass {
public class A {
public void m() { }
}
class B extends A {
}
public static void main(String args[]) {
new TestClass().new A() { public void m() { } };
}
}


this code compiles fine???but we have two public class A which is inside public class testClass ...is this okie



You can append public, private, protected, abstract, final(but not final and abstract both), strictfp to the inner-class-name. You can also append static, but then the inner class will become static nested class( I think that is the name for that).
[ September 28, 2008: Message edited by: Arijit Daripa ]

SCJP 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we have public inner class