标签:字符 结束 etc print etag icc 动物类 main demo1
1package debug; 2 3/* 4 1、定义一个公共的动物类,包含名字、年龄、颜色和吃饭东西方法 5 2、定义一个猫类,继承动物类,同时拥有玩游戏的本领 6 3、定义一个狗类,继承动物类,同时拥有看门的本领 7/ 8 9class Animal{10private String name;11privateint age;12private String color;1314public Animal() {1516 }1718publicAnimal(String name,int age,String color) {19this.name = name;20this.age = age;21this.color = color;22 }2324public StringgetName() {25return name;26 }2728publicint getAge() {29return age;30 }3132public StringgetColor() {33return color;34 }3536publicvoid setName(String name) {37this.name = name;38 }3940publicvoid setAge(int age) {41this.age = age;42 }4344publicvoid setColor(String color) {45this.color = color;46 }4748publicvoid eat() {49System.out.println("饿了就要吃饭");50 }51}5253classCatextends Animal{54public Cat() {}5556publicCat(String name,int age,String color) {57super(name,age,color);58 }5960publicvoid playGame() {61System.out.println("猫都会玩游戏了");62 }6364}656667publicclass Demo16 {68publicstaticvoid main(String[] args) {69Cat c1 =new Cat();70c1.setName("tom");71c1.setAge(3);72c1.setColor("white");73 c1.playGame();74System.out.println("猫的名字叫:" + c1.getName() + "\n年龄为:" + c1.getAge() + "\n颜色为:" +c1.getColor());7576Cat c2 =newCat("jerry",5,"yellow");77System.out.println("猫的名字叫:" + c2.getName() + "\n年龄为:" + c2.getAge() + "\n颜色为:" + c2.getColor());78 }7980}上面代码是经常调试修改后正确的代码,下面将在调试过程中遇到的错误一一罗列如下:
1、在类中的方法经常会忘记带上方法的返回类型: String, int, void.....
2、在每句结束时忘记以分号结束该语句
3、在输出语句中的字符串连接涉及对象调方法时忘记以()结束
标签:字符 结束 etc print etag icc 动物类 main demo1
原文地址:http://blog.51cto.com/14080124/2329641