# #看别人博客, it's confusing to find these topics, so write them down in your blog.
3) Which of the following options will compile properly: C
A:int i = Integer.valueOf(1.2); 理由:Integer.valueOf(int/String);只有这两种参数 B:char c = "a";不能将字符串类型转化为字符型 C:byte b = 127; D: float f = 1.3;理由:不能将double型转换为float类型
4) The result of the following code is: a
public static void main(String[] args){ String s; System.out.println("s = " + s); } A:由于String s没有初始化,代码不能通过编译; B:抛出NullPointException异常 C:输出s=; D:输出s = null;
If we don't get it right, we might choose D as the wrong option, and the reason for selecting a in the above question is that the local variable must be initialized;
However, if one of our classes has a property of type string, it is initialized with "null" by default, and when we make the output of this property we choose the D option.
6) How many objects does the above statement produce altogether? Answer: A
String a = "aaaaaa";
String B = a.substring (2, 3);
String C = a.tostring ();
String d = new Stringbufer (a). ToString ();
A: 3, B: 4 C: 5 d:6
Resolution: The first is an object, the second is an object, the third is the same object as the first object (this is the concept of a string buffer pool inside), the fourth is a new object (because he uses new is to emphasize I want a new object, not the old) If there is another expression: string Str=new string ("aaaaaa"), this is also a new object (as long as the object created by using new is a new object), and the objects above are not the same.
7, the following program output is: C
A:输出null; B:抛出异常 C:输出0; D:输出1
package org.wrh.programbeautiful; Public class TestDemo01 {private static int i; public static void say () {System. out . println ( +i++); } public static void main (string[] args) {(TestDemo01) null). Say (); //This does not know why the output is: 0 //say (); This result is not as much as 1, }}
Cast the null type to the TESTDEMO01 type, and then call the Say function in the TestDemo01 class, but why is the output 0???
Can you explain to me, please.
Here's the source of the above topic.
Some small knowledge points in Java (interview)