[java]一个较为健全的类

来源:互联网 发布:linux more 到最后 编辑:程序博客网 时间:2024/04/29 11:13


一个较为健全的类

package com.ma.demo4;public class Demo {private String name;private int age;public Demo() {}public Demo(String name, int age) {this.name = name;this.age = age;}public void setName(String name) {this.name = name;}public String getName() {return name;}public void setAget(int age) {this.age = age;}public int getAge() {return age;}public void show() {System.out.println(this.name + "   " + this.age);}}


package com.ma.demo4;public class Test {public static void main(String[] args) {Demo dd = new Demo();dd.setAget(22);dd.setName("毛主席");dd.show();System.out.println("----------");Demo dd2 = new Demo("屈原", 22);dd2.show();}}




阅读全文
0 0