java笔试题(面试题)系列之一

1)

1 public class Test01 {
2 
3     public static void main(String[] args) {
4         int a = 5;
5         System.out.println("value is " + ((a<5)?10.9:9));
6     }
7 
8 }

输出结果为:9.0

分析:因为有10.9,所以会发生数据类型自动转换,9自动转换为9.0,因此输出结果为9.0.具体数据类型转换详解,请查看本人博客http://www.cnblogs.com/XuGuobao/p/7229881.html

2)

 1 public class Test03 {
 2 
 3     public static void main(String[] args) {
 4         int m = 5,n = 5;
 5         if((m != 5) && (n++ == 5)){}
 6         System.out.println("a." +n);
 7         
 8         m = n = 5;
 9         if((m != 5) & (n++ == 6)){}
10         System.out.println("b." +n);
11         
12         m = n =5;
13         if((m == 5) || (n++ == 5)){}
14         System.out.println("c." +n);
15         
16         m = n =5;
17         if((m == 5) | (n++ == 6)){}
18         System.out.println("d." +n);
19         
20         int a = 1,b = 2;
21         int c = a & b;
22         System.out.println("a % b" +c);
23     }
24 
25 }

输出结果为:

a.5
b.6
c.5
d.6
a % b0

 

3)

 1 class Base{
 2     int i;
 3     Base(){
 4         add(1);
 5         System.out.println(i);
 6     }
 7     void add(int v){
 8         i += v;
 9         System.out.println(i);
10     }
11     void print(){
12         System.out.println(i);
13     }
14 }
15 class MyBase extends Base{
16     MyBase() {
17         add(2);
18     }
19     void add(int v){
20         i += v*2;
21         System.out.println(i);
22     }
23 }
24 
25 public class TestClu {
26 
27     public static void main(String[] args) {
28         go(new MyBase());
29     }
30 
31     static void go(Base b) {
32         b.add(8);
33     }
34 }

输出结果为:

2
2
6
22

posted @ 2017-07-24 19:56  XuGuobao  阅读(294)  评论(0编辑  收藏  举报