当前位置: 技术问答>java相关
欢迎讨论~!
来源: 互联网 发布时间:2015-03-24
本文导语: class Librarian { String passName; public Librarian() { passName="《Thinking in Java》"; } void issueBook(String recName) { System.out.println("The name of the book is "+recName); } public static void main(String args[]) { Librarian j=new Librarian(...
class Librarian
{
String passName;
public Librarian()
{
passName="《Thinking in Java》";
}
void issueBook(String recName)
{
System.out.println("The name of the book is "+recName);
}
public static void main(String args[])
{
Librarian j=new Librarian();
j.issueBook(passName);
}
};
/*错误为:在静态上下文中不能引用非静态变量passName,最简单的改法~!
最简洁的代码,如何更改~!欢迎讨论~!*/
{
String passName;
public Librarian()
{
passName="《Thinking in Java》";
}
void issueBook(String recName)
{
System.out.println("The name of the book is "+recName);
}
public static void main(String args[])
{
Librarian j=new Librarian();
j.issueBook(passName);
}
};
/*错误为:在静态上下文中不能引用非静态变量passName,最简单的改法~!
最简洁的代码,如何更改~!欢迎讨论~!*/
|
class Librarian
{
String passName;
public Librarian()
{
passName="《Thinking in Java》";
}
void issueBook(String recName)
{
System.out.println("The name of the book is "+recName);
}
public static void main(String args[])
{
Librarian j=new Librarian();
j.issueBook(j.passName);
}
};
{
String passName;
public Librarian()
{
passName="《Thinking in Java》";
}
void issueBook(String recName)
{
System.out.println("The name of the book is "+recName);
}
public static void main(String args[])
{
Librarian j=new Librarian();
j.issueBook(j.passName);
}
};