尚学堂第四章作业

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","abc@emai.com");
		netuser1.outputinfo();
		InternetUser netuser2 = new InternetUser(002,"123");
		netuser2.outputinfo();
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值