| 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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
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
|
 |
 |
|
|
subject: can we have public inner class
|
|
|