7.阅读下面程序,修改程序中错误的地方(提示:共三处)。 1. class Person{ 2. String name; 3. int age; 4. String sex;
5. public Person(String name,int age,String sex){ 6. this.name=name; 7. this.age=age; 8. this.sex=sex; 9. }
10. public void toString(){
11. return \12. } 13. }
14. public class TestPerson{
15. public static void main(String args[]){ 16. Person p=new Person(); 17. p.name=\张三\18. p.age=20; 19. p.sex=\男\
20. System. out.println (Person.tostring ()); 21. } 22. }
8.写出下列程序代码的运行结果。 public class Test( int x=4;
public static void main (String argv [ ] ) { Test t=new Test (); t.x++;
change (t);
System.out.println (t.x); }
static void change (Test m) { m.x+=2; } }
四、编程题.
1.编写一个Java程序Suansu.java,定义两个整型变量a和b,使用构造方法初始化a为10,b为5,