尚学堂第四章作业

1.C 构造器有返回值
2.D
3. AD 静态方法中不能用this (类都没有初始化好,怎么用实例this)
4. CD 类方法是static方法,实例方法就是一般的非static方法
5.C

/**
编程一
*/
public class Person {
private String name;
private int age;
	
	Person(String name,int age){
		this.name  = name;
		this.age = age;
	}
	
	public static void main(String[] args) {
		Person p1= new Person("张三",18);
		System.out.println("人物姓名为:"+p1.name);
		System.out.println("人物年龄为:"+p1.age);
	}
}
/**
编程二
*/
public class Circle {	

	private static double r;
	
	Circle(double r){
		Circle.r=r;
	}
	
	void getArea(double r){
		System.out.println("该园面积为:"+Math.PI*r*r);
	}
	
	void getPerimeter(double r) {
		System.out.println("该圆的周长为:"+2*Math.PI*r);
	}
	
	public static void main(String[] args) {
		Circle c = new Circle(8.0);
		c.getArea(r);
		c.getPerimeter(r);
	}
}
public class InternetUser {
	int id;
	String pwd;
	String email;
	
	//构造函数1
	InternetUser(int id,String pwd,String email){
		this.id = id;
		this.pwd = pwd;
		this.email = email;
	}
	
	//构造函数2
	InternetUser(int id,String pwd){
		this.id = id;
		this.pwd = pwd;
		this.email=id+"@gameschool.com";
	}
	
	//输出函数,验证重载是否正确
	public void outputinfo() {
		System.out.println("用户名为:"+id);
		System.out.println("用户密码为:"+pwd);
		System.out.println("email地址为:"+email);
	}
	
	public static void main(String args[]) {
		InternetUser netuser1 = new InternetUser(001,"123","[email protected]");
		netuser1.outputinfo();
		InternetUser netuser2 = new InternetUser(002,"123");
		netuser2.outputinfo();
	}
}

你可能感兴趣的:(尚学堂第四章作业)