03 类与对象.pptVIP

  • 2
  • 0
  • 约4.72千字
  • 约 31页
  • 2016-11-28 发布于河南
  • 举报
03 类与对象

* public class Test1 { public static void main(String[] args) { Student1 s = new Student1(); s.id=15; s.name=王刚; s.show(); Student1 m = new Student1(); m.id=16; m.name=李红; m.show(); Student1 n=m; n.show(); } } * 0x8000 0x3000 15 王刚 16 李红 0x8000 0x3000 0x3000 s m n 权限修饰符: public 公共权限 可在类外代码中使用,即被其它类使用。 用法:类名.属性或方法 private 私有权限 只能在类内代码中使用,即本类使用 用法:直接属性或方法 实现封装性的原理: 外部通过公有函数访问私有数据。 * * public class Student2 { private int id; private String name; public void setId(int id) { this.id=id; } public int getId() { return id

文档评论(0)

1亿VIP精品文档

相关文档