求Java大神编写程序
展开全部
public class Main {
public static void main(String[] args) {
//输出货物总重
System.out.println(Obj.nSum);
//增加货物
Obj A = new Obj(1);
Obj B = new Obj(2);
System.out.println(Obj.nSum);
Obj C = new Obj(3);
Obj D = new Obj(4);
System.out.println(Obj.nSum);
System.out.println(A.getM_a() + " + " + B.getM_a() + " + " + C.getM_a() + " + " + D.getM_a() + " = " + Obj.nSum);
}
}
class Obj {
public static int nSum;
private int m_a;
public Obj(int m_a) {
this.m_a = m_a;
nSum += m_a;
}
public int getM_a() {
return m_a;
}
}
public static void main(String[] args) {
//输出货物总重
System.out.println(Obj.nSum);
//增加货物
Obj A = new Obj(1);
Obj B = new Obj(2);
System.out.println(Obj.nSum);
Obj C = new Obj(3);
Obj D = new Obj(4);
System.out.println(Obj.nSum);
System.out.println(A.getM_a() + " + " + B.getM_a() + " + " + C.getM_a() + " + " + D.getM_a() + " = " + Obj.nSum);
}
}
class Obj {
public static int nSum;
private int m_a;
public Obj(int m_a) {
this.m_a = m_a;
nSum += m_a;
}
public int getM_a() {
return m_a;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询