摘要: String 1.String是final类,不可被继承 2.内部是value[]的数组 private final char value[]; 3.不可变字符串 String s1 = "abc"; //字面量方式,"abc"被放到了常量池中 String s2 = "abc"; //这里s1 和 阅读全文
posted @ 2021-01-24 20:48 先生胡 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 单例设计模式 饿汉式模式 class Person{ //1.私有化构造器 private Person(){ //dosomething } //2.类内创建 该对象,同时要求该对象是static private static Person personInstance = new Person( 阅读全文
posted @ 2021-01-24 15:52 先生胡 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 包装类 jdk5.0之后增加自动拆箱和自动装箱 自动装箱 int num = 3; Integer in = num; //编译可以通过 ,拆箱写法 Integer in1 = new Integer(num); //不拆箱写法 自动拆箱 Integer in1 = new Integer(3); 阅读全文
posted @ 2021-01-24 11:13 先生胡 阅读(60) 评论(0) 推荐(0) 编辑
摘要: ==和equals ==: 若是基本数据类型比较,则只比较两个数值是否相等 若 == 比较引用型类型 则比较的是地址 int i = 3; int j = 3; double d = 3.0; char c = 3; System.out.println(i == j); //true System 阅读全文
posted @ 2021-01-24 10:35 先生胡 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 多态 多态的使用:虚拟方法调用 有了对象的多态性以后,我们在编译期,只能调用父类中声明的方法,但在运行期,我们实际执行的是子类重写父类的方法。 总结:编译,看左边;运行,看右边。 多态性的使用前提:类的继承关系,方法的重写 //多态举例 class Person{ int age = 3; publ 阅读全文
posted @ 2021-01-24 10:10 先生胡 阅读(18) 评论(0) 推荐(0) 编辑
摘要: this 理解为当前对象。 //测试 public static void main(String[] args){ Person person = new Person(3, "xiaoMing"); } //创建一个类: class Person{ int age; String name; p 阅读全文
posted @ 2021-01-24 09:14 先生胡 阅读(53) 评论(0) 推荐(0) 编辑