问题描述:

I want to refer to the variable of an object of a static nested class from the outer class. Would this work?

public class GuiApp {

static class book{

static book [] book = new book[1000];

static Boolean overdue;

static Boolean checkedOut;

static int bookNum;

static String personName;

static String dueDate;

static int month;

static int date;

static int year;

static String dateCheckedOut;

}

}

and later to refer to the variable String personName of book[50] from the outer class for example

book.book[50].personName = "Bob";

I'm not sure if I'm understanding this correctly so I want to know if this would work.

网友答案:

Before accessing an element of that array :

book.book[50].personName = "Bob";

You have to initialize that element :

book.book[50] = new GuiApp.book();

I would also advise against using the same name for the class and the array.

However, making all the properties of the book class static makes no sense, since it means that all the books would have the same values.

相关阅读:
Top