摘要:
1.包装类是什么 基本数据类型变为引用数据类型,每一个都是一个类。 Integer age = new Integer(18); int age = 18; 2.为什么要用包装类 (1)使基本数据类型具有类的特点,创建对象,调用类的方法,符合面向对象。 (2)基本数据类型的默认值各不相同int的为0 阅读全文
摘要:
1.英寸和厘米换算 1英寸 = 2.54厘米 value = float(input("请输入长度:")) unit = input("请输入单位:") if unit == 'in' or unit == '英寸': print('%f英寸 = %f厘米' % (value, value * 2. 阅读全文
摘要:
1.两个分支 if表达式和else后面要跟英文冒号,使用缩进的方式来表示层次结构,而不是花括号,通常为4个空格。 (1)判断闰年 year = int(input("请输入年份:")) if ((year % 4 == 0 and year % 100 != 0) or year % 400 == 阅读全文
摘要:
1.Object类源码 点击查看Object类源码-带注释 package java.lang; /** * Class {@code Object} is the root of the class hierarchy. * Every class has {@code Object} as a 阅读全文
摘要:
1.基本数据类型和引用数据类型转换比较 (1)基本数据类型转换 ① 自动类型转换:小->大 long g = 20; double d = 12.0f; ② 强制类型转换:大->小 float f = (float)12.0; int a = (int)1200L; (2)引用类型转换 ① 子类-> 阅读全文
摘要:
1.instanceof语法 x instanceof A:对象x是否是A类(或A类的子类)的对象,返回值为boolean类型。 A 也可为接口,x为A接口实现类对象。 x不是A类或A类的子类时,编译错误。 public void eat(Person person) { if (person in 阅读全文