Foreword
Whether you are starting a new job or into the workplace in the workplace N Big Brother ~ Of course, this N <3 ~, I guarantee you can not answer these ten questions - do not ask why I am so confident - these two questions or "horizontal "the javase
basis for the title, rumors white duck designated points, a test a prospective, ha ha.
As the architect of the future to become a man, right, you're not wrong, that is to say you look very open skin ~ Sen ~, what? You are white? I top you a lung, I cry bar fine, you should dare to do, the bar code fine 9527, saying How about you hurry to answer, see if you can answer a few questions.
A title
The following program is the problem? If there is a problem to explain, if there is no problem guessing what operating results
public static void main(String[] args){
short s = 1;
s=s+1;
System.out.println(s);
}
ps: it is big brother tinkling child, everyone put their mind to look at the results of the following analysis of the answers on small notebook ~
Analysis: s = s + 1
The results promoted int
type, again short
an error occurs when the type of assignment, because the range of large type can not be assigned to the range of small type, so the program will fail to compile error.
Title two
The following program is the problem? If there is a problem to explain, if there is no problem guessing what operating results
public static void main(String[] args){
short s = 1;
s+=1;
System.out.println(s);
}
ps: it is big brother tinkling child, everyone put their mind to look at the results of the following analysis of the answers on small notebook ~
Analysis: s += 1
seen as logically s = s + 1
results promoted to int type, again short
an error occurs when the type of assignment, because the range of large type can not be assigned to the range of small type. However, s=s+1
twice operation, +=
is an operator, only one operation , and with a cast of features, that s += 1
is s = (short)(s + 1)
, the program compiles without problems, the results are 2
.
Here, both wrong conscious point to the upper right corner of the article points a landlord Chan, duck! Congratulations to get the first
N+1
small white Medal of Honor naive accurate doubt, do not mind, just as the wind language Lan Xia curse Lane said: as long as the heart of justice, Xia Lan everywhere! So I just want to say is that Medal of Honor is also naive white Medal. hhhhhh, ~ Ai Aiai, do not fight do not fight ... ... Not the face. ~
Title three
The following program is the problem? If there is a problem to explain, if there is no problem guessing what operating results
public static void main(String[] args){
byte b1=1;
byte b2=2;
byte b3=1 + 2;
byte b4=b2 + b3;
System.out.println(b3);
System.out.println(b4);
}
ps: it is big brother tinkling child, everyone put their mind to look at the results of the following analysis of the answers on small notebook ~
Analysis: b3 = 1 + 2
1 and 2 are constants for fixed data, at compile time (compiler javac
), has been determined 1+2
result does not exceed the byte
type of range, a variable can be assigned to b3, and therefore b3=1 + 2
is correct. On the contrary, b4 = b2 + b3
, b2 and b3 are variable, the variable's value is likely to change, at compile time, the compiler javac
uncertain b2+b3
what the outcome is, and therefore will result in a int
type of processing, so the int
type can not be assigned to byte
type, so the compiler fails .
Title four
The following program is the problem? If there is a problem to explain, if there is no problem guessing what operating results
public static void main(String[] args){
short s = 32767;
s = (short)(s + 10);
System.out.println(s);
}
ps: it is big brother tinkling child, everyone put their mind to look at the results of the following analysis of the answers on small notebook ~
Analysis: s is defined as the short
maximum value of the range (2^15) - 1 = 32767
, after calculation, cast ( int
replaced short
), cut 2 bytes after indeterminate results, and because this value is outside the short
range of data types, thereby becoming negative results-32759
Here, four questions were wrong conscious article points to the upper right corner a landlord praise, as well as white students do not lose heart, I remember when the landlord just learning java, and Tencent in the live classroom lectures it is when that a teacher is that these types of questions, I have been wrong answer, the teacher put my landlord several times: the white students is you, you have got it wrong ... not to mention, Forget the past. So, white students do not lose heart Oh ~
Five questions
The following program is the problem? If there is a problem to explain, if there is no problem guessing what operating results
public static void main(String[] args) {
int a=0;
for (int i = 0; i >= a && i<100 ; i++){
a+=i;
}
System.out.println(a);
}
ps: it is big brother tinkling child, everyone put their mind to look at the results of the following analysis of the answers on small notebook ~
Analysis: This little no details as well as "routine", but simply mixed with some logic, so the segment points debug
of it, feel it, the result is 6
Title six
The following program is the problem? If there is a problem to explain, if there is no problem guessing what operating results
public static void main(String[] args) {
int x=4;
System.out.println("value is " + ((x>4) ? 99.9 : 9));
}
Analysis: This question I guess 99%
would be wrong - including myself - if I am wrong, then your result is that 9
, what? Your result 99.9
, the amount of this, if you are not bar the students fine then I suggest you go home farm, and I with you, you hoe to till the fields I uh uh uh ... what is it that the results, the results actually Shi 9.0
. . . The reason I was ever given haha careful not to dive too, if I had to estimate results java to 9 as the default integer floating point data types, of course I just inference, then know Gangster please comment and come out.
Title seven
The following program is the problem? If there is a problem to explain, if there is no problem guessing what operating results
public static void main(String[] args) {
//对于下面两句代码是否编译出错,很基础的哦
double d=3.10;
float f=3.10;
//对于下面两句代码是否编译出错,以及打印结果是多少
float a = 12345678.90123456789f;
double b=0.12345678901234567890;
float c=0.12345678901234567890f;
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
ps: it is big brother tinkling child, everyone put their mind to look at the results of the following analysis of the answers on small notebook ~
Analysis: 3.10
is a float, floating-point literal as the default double
type of processing, directly by the compiler; if it is float
the type must be added F
or f
, if not increase, not directly by the compiler, will get an error " loss of precision ", as also the solution very simple, first way: cast float f1=(float)3.10
; second way: direct conversion type does not increase F
or f
, ; 如 folat f2=3.10f
abc the print result of a = 1.2345679E7
, b = 0.12345678901234568
,c = 0.12345679
If you still do not know java floating-point type float
and double
can refer to this article
Title eight
Analysis following code, suppose the output result.
public static void main(String[] args) {
int a = 1; int b = 2;
System.out.println(a);
System.out.println(b);
change(a, b);
System.out.println(a);
System.out.println(b);
}
public static void change(int a, int b) {
a = a + b; b = b + a;
}
Analysis following code, suppose the output result.
public static void main(String[] args) {
int[] arr = {1,3,5};
System.out.println(arr[0]);
change(arr);
System.out.println(arr[0]);
}
public static void change(int[] arr) {
arr[0] = 200;
}
The problem is not analyzed, is to investigate the array, got it wrong boots child may understand the array is not particularly clear analysis, you can refer to this article java array definition, usage, and memory array Detailed analysis
Title nine
Operating results is what is it?
public static void main(String[] args) {
int i = 1, j = ++i;
System.out.println(i);
System.out.println(j);
}
Analysis: The estimate it will feel i=1,j=2
, Poof ha ha, you too simple, what? Your answer is i=1,j=1
? My brother tinkling home farm it with you. So what is the result? i=2,j=2
The reason is very simple, i actually a variable , j is a variable , before i is 1, then j experienced ++i
while on this experience, i have since increased ++
, and it is also 2.
Here, nine questions wrong more than half of the students consciously article points to the upper right corner a landlord praise, do not lose heart, just like the wind language Lan Xia curse Lane said: as long as the heart of justice, Xia Lan everywhere! We will continue to refuel wow! Red duck to architects road! ! !
Title ten
This problem mainly on the multi-state knowledge, involves the concept of transformation upward and downward transition, it is more difficult biased!
package Polymorphic;
//爷爷类
class Ye {
public String show(Sun obj) {
return ("Ye and Sun");
}
public String show(Ye obj) {
return ("Ye and Ye");
}
}
//爸爸类
class Fu extends Ye {
public String show(Fu obj) {
return ("Fu and Fu");
}
public String show(Ye obj) {
return ("Fu and Ye");
}
}
//儿子类
class Zi extends Fu {
}
//孙子类
class Sun extends Fu {
}
public class PolymorphicTest {
public static void main(String[] args) {
Ye y = new Ye();
Ye y2 = new Fu(); //向上
Fu f = new Fu();
Zi z = new Zi();
Sun s = new Sun();
System.out.println("第一题 " + y.show(f));
System.out.println("第二题 " + y.show(z));
System.out.println("第三题 " + y.show(s));
System.out.println("第四题 " + y2.show(f)); //到这里挂了???
System.out.println("第五题 " + y2.show(z));
System.out.println("第六题 " + y2.show(s));
System.out.println("第七题 " + f.show(f));
System.out.println("第八题 " + f.show(z));
System.out.println("第九题 " + f.show(s));
}
}
operation result
第一题 Ye and Ye
第二题 Ye and Ye
第三题 Ye and Sun
第四题 Fu and Ye
第五题 Fu and Ye
第六题 Ye and Sun
第七题 Fu and Fu
第八题 Fu and Fu
第九题 Ye and Sun
Analysis of the case would involve too much knowledge points, such as Golden upward polymorphic transition down, this is the basis of key basic essential, it is recommended refer to this article [blue font, click to enter]
Here are all the wood to the right of Big Brother pinch, if so, on behalf of the chiefs of all worship under white duck points -
Finally, each question has a point calculation, etc., how you? Courage to speak out, despite the killing landlord
If this article there is a little bit of help to you, then please point a chant praise, thank you ~
Finally, if there is insufficient or is not correct, please correct me criticism, grateful!
I welcome you to focus on the public number, to explore technology, yearning technology, the pursuit of technology