Your code is fine.
Looking at your error you might be having troubles with incorrect packages..
Exception in thread "main" java.lang.NoClassDefFoundError:
Nestedclasstest/NestedClassTest$Y
...
Caused by: java.lang.ClassNotFoundException:
nestedclasstest.NestedClassTest$Y
nestedclasstest vs Nestedclasstest. Refer here for reference
just recompile and run again, should work.