DAY06

1.方法的可变参数个数传输:

定义一个数组

public static void main(String[] args)
/**
 * Person1类
 * @author Daniel
 *
 */
public class Person1 {
	/**
	 * 用数组的方式传递可变个数的参数
	 * @param args
	 */
	public void printInfo(String[] args)
	{
		for(int i = 0; i < args.length; i++)
		{
			System.out.println(args[i]);
		}
	}
	/**
	 * 用Java自己的...来操作和上面一样的
	 * @param args
	 */
	public void printInfo1(String... args)
	{
		for(int i = 0; i < args.length; i++)
		{
			System.out.println(args[i]);
		}
	}
}
/**
 * 调试
 * @author Daniel
 *
 */
public class Test4 
{
	public static void main(String[] args)
	{
		Person1 p1 = new Person1();
		String[] ss = new String[] {"张三","11"};
		String[] sss = new String[] {"go"};
		p1.printInfo(ss);
		p1.printInfo1(sss);
	}
}

2.方法的参数传递:

Java里只有值传递。
在这里插入图片描述
在这里插入图片描述

3.包和引用import:

import导入外包

4.封装和隐藏:

先把属性设为私有(private),
通过编写public类型setXxx()和getXx()方法来设置属性和获取属性,比如对age去写get和set方法,那么方法名就setAge,getAge。

private int age;

public int getAge()
{
	return age;
}

5.四种访问权限修饰符:

在这里插入图片描述

6.类的构造方法:

在这里插入图片描述

/**
 * 初始化age,name
 * @author Daniel
 *
 */
public class Person1 
{
	public Person1(int a,String n)
	{
		age = a;
		name = n;
	}
	public int age;
	public String name;
}

/**
 * 调试
 * @author Daniel
 *
 */
public class Test1 
{
	public static void main(String[] args)
	{
		Person1 p1 = new Person1(12,"张三");
		System.out.println(p1.age);
		System.out.println(p1.name);
	}
}

7.构造器重载

8.this关键字:

在这里插入图片描述
在这里插入图片描述

9.JavaBean:

/**
 * javabean
 * 私有的属性
 * 属性对应的set和get方法
 * @author Daniel
 *
 */
public class Person2 
{
	private String name;//名字
	private int sex;//性别0男1女
	private int age;//年龄
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getSex() {
		return sex;
	}
	public void setSex(int sex) {
		this.sex = sex;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	
	 
	
//	public void setName(String name)
//	{
//		this.name = name;
//	}
//	public String getName()
//	{
//		return this.name;
//	}
//	
//	public void setSex(int sex)
//	{
//		this.sex = sex;
//	}
//	public int getSex()
//	{
//		return this.sex;
//	}
//	
//	public void setAge(int age)
//	{
//		this.age = age;
//	}
//	public int getAge()
//	{
//		return this.age;
//	}
}
public class Test2
{
	public static void main(String[] args)
	{
		Person2 p2 = new Person2();
		p2.setName("张三");
		p2.setSex(0);
		p2.setAge(20);
		System.out.println(p2.getAge());
		System.out.println(p2.getSex());
		System.out.println(p2.getName());
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值