public class Example3_11
{
private int money;
Example3_11()
{
money=2000;
}
private int getMoney()
{
return money;
}}
public class Main
{
public static void main(String args[])
{
Example3_11 exa=new Example3_11();
exa.money=3000;
int m=exa.getMoney();
System.out.print("money="+m);
}}
这个程序 是因为 用了 private 所谓 main函数 就不能运用 Example3_11这个类的方法了吗???
我新手 希望大家帮帮哈
{
private int money;
Example3_11()
{
money=2000;
}
private int getMoney()
{
return money;
}}
public class Main
{
public static void main(String args[])
{
Example3_11 exa=new Example3_11();
exa.money=3000;
int m=exa.getMoney();
System.out.print("money="+m);
}}
这个程序 是因为 用了 private 所谓 main函数 就不能运用 Example3_11这个类的方法了吗???
我新手 希望大家帮帮哈
public class Example3_11 {
private static int money; //static类型的,你才能exa.money这么用呀 Example3_11() {
money = 2000;
} private int getMoney() {
return money;
}//}//public class Main {
public static void main(String args[]) {
Example3_11 exa = new Example3_11();
exa.money = 3000;
int m = exa.getMoney();
System.out.print("money=" + m); }
}//}
另外你要给getmoney()个参数,没参数返回什么
private int getMoney(int money)
{
this.money=money;
return monty;}
这样就应该没问题了。
{
private int money;
Example3_11()
{
money=2000;
}
private int getMoney()
{
return money;
}
public static void main(String args[])
{
Example3_11 exa=new Example3_11();
exa.money=3000;
int m=exa.getMoney();
System.out.print("money="+m); }
}
类型 Example3_11 中的方法 getMoney()不可视
系统编译的时候提示说是这个
是因为不是一个类别的事情吗???
public class Example3_11{
private int money;
Example3_11(){
money=2000;
}
private int getMoney(){
return money;
}
public static void main(String args[]){
Example3_11 exa=new Example3_11();
exa.money=3000;
int m=exa.getMoney();
System.out.print("money="+m);
}
}
Activation.main: 警告: sun.rmi.activation.execPolicy 系统
属性未被指定且 ExecPermissions/ExecOptionPermissions
均未被授权。随后的激活尝试失败,原因是对
ExecPermission/ExecOptionPermission 的权限检查失败。
这是什么意思??
2、一个JAVA文件中,只能有一个public类;
3、楼主的代码格式不知道是否是无意识的这样写,看的不是很习惯,7楼那样格式的我比较喜欢。
好戏那个不是一个JAVA文件中就能有一个PUBLIC 类吧 应该就能有一个MAIN 吧???
还有 我拿代码 不太会粘贴 一发表就成那样子了 我也不想 希望有人能指教我一下 该如何贴代码! 谢谢
class Example3_11 { private int money; Example3_11() {
money = 2000;
} public int getMoney() {
return money;
} public void setMoney(int m) {
money = m;
}
}public class Main { public static void main(String args[]) {
Example3_11 exa = new Example3_11();
exa.setMoney(3000);
int m = exa.getMoney();
System.out.print("money=" + m); }
}
private,public,default,protected
{
private int money;
Example3_11()
{
money=2000;
}
public int getMoney()
{
return money;
}
public void setMoney(int money){
this.money=money;
}}
public class Main
{
public static void main(String args[])
{
Example3_11 exa=new Example3_11();
exa.setMoney(2000);
int m=exa.getMoney();
System.out.print("money="+m); } }
private 只能在本类中访问
protect 、default在同一个包中访问
自己定义一个setXXX的方法,就像#26那样
{
return money;
} 怎么可能是private?你不是public至少也得是protected的吧...