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.
Using the nested class will make your code more readable and provide better encapsulation. Non-static nested classes (inner classes) have access to other members of the outer/enclosing class, even if they are declared private.
What is the scope of a class nested inside another class? Explanation: It depends on the access specifier and the type of inheritance used with the class, because if the class is inherited then the nested class can be used by subclass too, provided it's not of private type.
If the inner class defined as private and protected, can outer class access the members of inner class? Yes.
I have some situation that I want to use inner class of another class in another class. like...
public class ListData {
public static class MyData {
public String textSongName, textArtistName, textDuration, textDownloadPath,
textSongSize, textAlbumName, textUrl;
public boolean enable;
public MyData(String songName, String artistName, String duration,
String downloadPath, String songSize, String albumName,
String url, boolean e) {
textSongName = songName;
textArtistName = artistName;
textDuration = duration;
textDownloadPath = downloadPath;
textSongSize = songSize;
textAlbumName = albumName;
textUrl = url;
enable = e;
}
}
}
now I want to use Mydata class in another.
how can I do this?
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With