4.26学习内容——类、包装类

1.类的主方法——Main方法

1.主方法是静态的,如果在主方法中调用其他方法,则该方法必须也是静态的。
2.主方法没有返回值。

2.eclipse中设置程序参数

3.对象的特性

1.对象的创建:使用new操作符调用构造方法就可以创建一个对象
2.对象的引用:

public class DuiXiangTest {

	int i = 365;
	public int getname() {
		return i;
	}
	
	public static void main(String[] args) {
		DuiXiangTest a = new DuiXiangTest();//a是对象的一个引用
		System.out.println(a.getname());//可以用引用来调用
		System.out.println(new DuiXiangTest().getname());//也可以直接来调用
	}
}

3.对象的使用

public class YinYong {

	String a = "刘情利";//成员变量
	
	public void call(){
		System.out.println("调用了call方法");
		System.out.println(a);
	}
	
	public static void main(String[] args) {
		YinYong a = new YinYong();
		a.call();//调用成员方法
		System.out.println(a.a);//输出成员变量
	}
}

在这里插入图片描述

4.对象的销毁

4.整数类型包装类——Integer类

用于封装int 类型数据,基本操作如下

public class IntegerTest {
    
	public static void main(String[] args) {
		System.out.println("int类型的最小值"+Integer.MIN_VALUE);
		System.out.println("int类型的最大值"+Integer.MAX_VALUE);
		System.out.println("int类型所占用的长度"+Integer.SIZE);
		System.out.println("int类型的类型"+Integer.TYPE);
		
		Integer inte1 = new Integer(123);
		System.out.println(inte1);
		Integer inte2 = new Integer("321");//两种构造方法
		System.out.println(inte2);
		
		Integer inte3 = Integer.valueOf(123456);//一种赋值方法
		System.out.println(inte3);
		
		int a = Integer.parseInt("1234");//转换成int类型
		System.out.println(a+1);
		
		int b = inte2.intValue();//转换成int类型
		System.out.println(b-1);
		
		String er = Integer.toBinaryString(12);//转换成2进制数
		System.out.println("11的二进制表示为"+er);
		
		String liu = Integer.toHexString(14);
		System.out.println("14的十六进制表示为"+liu);
		String ba = Integer.toOctalString(9);
		System.out.println("9的十六进制表示为"+ba);
		
		String renyi = Integer.toString(15,16);//15的16进制表示
		System.out.println(renyi);
	}
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值