---
title: "有意思的问题2"
author: "yanlei3032"
date: "2011-09-26T14:58:55Z"
tags: []
categories: ["编程语言"]
slug: "2"
draft: false
lastmod: "2013-07-18T21:07:07Z"
id: 1180673
url: "https://dls.iteye.com/blog/1180673"
---

\[code=&quot;第一个输出和第二个输出的有什么区别&quot;]public static void main(String\[] args)  
    {  
        Object obj=null;  
        System.out.println(String.valueOf(obj));  
        System.out.println(String.valueOf(null));  
    }  
   第一个打印调用valueOf(Object obj)，valueOf(char data\[])，第二个打印调用 java执行重载方法中，会选取精确性更强的方法

下面这段代码执行结果和你预期的是一样的吗？

\[code=&quot;java&quot;]//父类  
public class ConParent {  
public ConParent() {  
System.out.println(&quot;start parent Constructor&quot;);  
show();  
System.out.println(&quot;end parent Constructor&quot;);  
}

public void show() {  
System.out.println(&quot;i am parent&quot;);  
}

}

//子类  
public class ConChild extends ConParent {

private int i = 1;// 初时变量为1

public ConChild(int i) {  
this.i = i;  
System.out.println(&quot;child Constructor init i :&quot; + i);  
}

public void show() {  
System.out.println(&quot;i am child child :&quot; + i);  
}  
}

//测试类  
public class ConTest {

public static void main(String\[] args) {  
new ConChild(5);  
}  
}

byte和string的转换，不要随便把byte放在string中存贮。

\[code=&quot;java&quot;]

package com.util;

public class Test {

/\**  
\* @param args  
\*/  
public static void main(String\[] args) {  
byte bts\[] = new byte\[] {-77};  
String str = null;  
str = new String(bts);  
byte\[] tempBytes = str.getBytes();  
for(byte bt : tempBytes) {  
System.out.println(bt);  
}  
}

}