Code Description 1 The following is the correct
A: code can be compiled to run, output "AB.AB".
B: code can be compiled to run, the output of "AA".
C: code can be compiled to run, output "AB.B".
D: code can be compiled to run, output "AB".
Answer: C
Resolution:
A reference to a pointing object
A reference to an object B b
A reference to an object x
B y pointing object reference
Operate in the process, a reference point x of the object A is connected to B, the object A is also changed to AB
Then again a reference point to the object address x y pointed, this time reference is A, x, y point to the same object AB
The reference b no change, still pointing to the object B.
Passing parameters in Java are passed by value, it is not passed by reference,
Graphic:
2 The following description is correct
A: output: 13
B: Statement: b6 = b4 + b5 compile error
C: Statement: b3 = b1 + b2 compile error
D: runtime exception is thrown
Answer: C
Resolution:
The modified final variables are constants, where b6 = b4 + b5 can be seen b6 = 10;
At compile time has become b6 = 10 and b1 and b2 are the byte type, java them when the lifting calculation type int, and then calculated, b1 + b2 after calculation already int type, assigned to b3, b3 is a byte type, type does not match, the compiler will not pass, it needs to be cast.
In Java byte, when short, char calculation will be promoted to int type.
3 Which of the following statements are true
A: Examples of the method can be called the direct superclass instance method
B: 实例方法可直接调用超类的类方法
C:实例方法可直接调用其他类的实例方法
D: 实例方法可直接调用本类的类方法
答案:D
解析:
类方法就是静态方法。其它的就是实例方法
实例方法可以对当前对象的实例变量进行操作,也可以对类变量进行操作,但类方法不能访问实例变量。实例方法必须由实例对象来调用,而类方法除了可由实例对象调用外,还可以由类名直接调用。
另外,在类方法中不能使用 this 或 super。 关于类方法的使用,有如下一些限制:
1 在类方法中不能引用对象变量。
2 在类方法中不能使用super、this关键字。
3 在类方法不能调用类中的对象方法。
与类方法相比,实例方法几乎没有什么限制:
1 实例方法可以引用对象变量(这是显然的),也可以引用类变量。
2 实例方法中可以使用super、this关键字。
3 实例方法中可以调用类方法。
4 下列描述正确的有哪些
byte b1=1,b2=2,b3,b6;
final btye b4=4,b5=6;
b6=b4+b5;
b3=(b1+b2);
System.out.println(b3+b6);
A: 输出结果:13
B: 语句:b6=b4+b5编译出错
C: 语句:b3=b1+b2编译出错
D: 运行期抛出异常
答案:C
解析:
被final修饰的变量是常量,这里的b6=b4+b5可以看成是b6=10;在编译时就已经变为b6=10了
而b1和b2是byte类型,java中进行计算时候将他们提升为int类型,再进行计算,b1+b2计算后已经是int类型,赋值给b3,b3是byte类型,类型不匹配,编译不会通过,需要进行强制转换。
Java中的byte,short,char进行计算时都会提升为int类型。
5 下列代码输出正确的是
A:505000
B:0
C:510050
D:5050
Answer: B
Resolution:
This is because the jvm in dealing with i = i ++, will create a temporary variable to receive the value of i ++ is, and then returns the value of the temporary variable, the value returned again to receive a variable on the left, so that is i though from but the increase has been assigned a 0, so the result is 0 the natural output.
count = count ++ principle is:
the TEMP = COUNT; (left COUNT)
COUNT = COUNT +1; (Right COUNT)
COUNT = the TEMP; has been (left COUNT) 0
COUNT = COUNT ++ principles
temp = count +1 (right-count)
COUNT = the TEMP (left count)