I got an error when I wrote this code, so make a note.
public class Hoge {
private class Fuga(){
public String name;
}
public static void main(String[] args) {
Fuga fuga = new Fuga();
}
}
No enclosing instance of type Hoge is accessible.
Must qualify the allocation with an enclosing instance of type Hoge
(e.g. x.new A() where x is an instance of Hoge).
I can't access the inside of the Hoge class Error!
public class Hoge {
//Make it a static class
private static class Fuga(){
public String name;
}
public static void main(String[] args) {
Fuga fuga = new Fuga();
}
}
public class Hoge {
private static class Fuga(){
public String name;
}
public static void main(String[] args) {
//Instantiate Hoge and then instantiate Fuga
Hoge hoge = new Hoge();
Fuga fuga = hoge.new Fuga();
//You can do this
Fuga fuga2 = new Hoge().new Fuga();
}
}