how to use nested class in another class in java?

夙愿已清 提交于 2019-12-03 07:39:04
ListData.MyData myData = new ListData.MyData();

Static Nested Classes

OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();

Inner Classes

OuterClass.InnerClass innerObject = outerObject.new InnerClass();

More about Nested Classes

If you can create inner class object from other class that is out of scope from your enclosing class than you should use its fully qualified name.... Here , your outer class is ListData and your Inner class is Mydata and we call Mydata from another class eg. YourData.. than we can use below statement..

Syntax : outerclass.innerclass = new outerclass.innerclass();

=> ListData.MyData objectname = new ListData.MyData();

NOTE : this can use only when innner class is static..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!