aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class" Watch "inner class" New topic

inner class

peter kens

Joined: Jul 15, 2002
Posts: 4
from mughal's page 229

public class AccessInTopLevelClass {
public void nonStaticMethod() {
System.out.println("nonstaticMethod in AccessInTopLevelClass ");
private static class NestedTopLevelClass {
private static int i;
private int j;
public static void staticMethod() {
System.out.println("staticMethod in NestedTopLevelClass");


interface NestedTopLevelInterface1 {
int Y2K = 2000;
protected static class NestedTopLevelClass1 implements NestedTopLevelInterface1 {
private int k = Y2K;
public void anotherNonStaticMethod() {
//int jj = j;
int ii = i;
int kk = k;
public static void main (String args[]) {
int ii = i;
//int kk = k;
when i compile the above java file
this is the output
I want to run this
when i say " java NestedTopLevelClass1 "
it says
"Exception in thread "main" java.lang.NoClassDefFoundError: NestedTopLevelClass1"
So How do i Run it ?
Thank you in Advance
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Hi Peter,
The full name of a nested top-level calss includes the name of the class it is defined in ( See example on pg 226 mughal's ) . What this means is if you have a nested top level class X defined in a class Y , the full name of the class X would be Y$X . See the naming convention explained for example 7.1 on page 226 ( mughals ) .
In your code NestedTopLevelClass1 is defined in NestedTopLevelClass which in turn is defined in AccessInTopLevelClass.
So to execute NestedTopLevelClass1 you'd need the following line -
java AccessInTopLevelClass$NestedTopLevelClass$NestedTopLevelClass1.
Have a look at the names of the class files created to get the idea.
Ashish H.
I agree. Here's the link:
subject: inner class