码迷,mamicode.com
首页 > 其他好文 > 详细

易出错的代码整理

时间:2017-07-12 15:10:56      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:code   str1   pre   out   als   str   extend   end   style   

 1 public class HelloA {
 2     public HelloA() {
 3         System.out.println("HelloA");
 4     }
 5 
 6     {
 7         System.out.println("lam A class");
 8     }
 9     static {
10         System.out.println("static A");
11     }
12 
13 }
 1 public class HelloB extends HelloA {
 2     public HelloB() {
 3         System.out.println("HelloB");
 4     }
 5 
 6     {
 7         System.out.println("lam B class");
 8     }
 9     static {
10         System.out.println("static B");
11     }
12 
13     public static void main(String[] args) {
14         new HelloB();
15     }
16 }

执行结果:
1
static A 2 static B 3 lam A class 4 HelloA 5 lam B class 6 HelloB

 

1 public class Test {
2     public static void main(String[] args) {
3         String str1 = "Hello";
4         String str2 = "He" + new String("llo");
5         System.out.println(str1 == str2);
6         str2 = "He" + "llo";
7         System.out.println(str1 == str2);
8     }
9 }

比较结果:

false

true

易出错的代码整理

标签:code   str1   pre   out   als   str   extend   end   style   

原文地址:http://www.cnblogs.com/qq634571685/p/7125791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!