面试题

现在的公司开始变着花样的出面试题,大部分都是基础题,看了一下,觉得自己的基础还是不行,收藏这几个,以后备用

Question  1
class JMM119 {
    public static void main (String[] args) {
        int i = 0, j = 9;
        l1:
        do {
            l2:
          if (j < 4) {
              break l2;
          } else if (j-- < 7) {continue;}
         
          i++;
        } while (i++ < 7);
        System.out.print(i + "," + j);
    }
}
What is the result of attempting to compile and run the program?
a.  Prints: 4,7
b.  Prints: 6,6
c.  Prints: 6,5
d.  Prints: 6,4
e.  Prints: 7,5
f.  Prints: 8,4
g.  Run-time error
h.  Compile-time error
i.  None of the above

Question  2
package com.dan.chisholm;
public class A {
  public void m1() {System.out.print("A.m1, ");}
  protected void m2() {System.out.print("A.m2, ");}
  private void m3() {System.out.print("A.m3, ");}
  void m4() {System.out.print("A.m4, ");}

class B {
  public static void main(String[] args) {
    A a = new A();
    a.m1();  // 1
    a.m2();  // 2
    a.m3();  // 3
    a.m4();  // 4
}}
Assume that the code appears in a single file named A.java. What is the result of attempting to compile and run the program?
a.  Prints: A.m1, A.m2, A.m3, A.m4, 
b.  Compile-time error at 1.
c.  Compile-time error at 2.
d.  Compile-time error at 3.
e.  Compile-time error at 4.
f.None of the above

Question  3
class GFM13 {
  static byte a; static short b; static char c;
  static int d; static long e; static String s;
  public static void main(String[] args) {
    System.out.println(a+b+c+d+e+s);
}}
What is the result of attempting to compile and run the program?
a.  Prints: 00000null
b.  Prints: 00000
c.  Prints: 0null
d.  Prints: 0
e.  Prints: null
f.  Compile-time error
g.  Run-time error
g.None of the above

Question  4
class GFC301 {
  private String name;
  public GFC301(String name) {this.name = name;}
  public void setName(String name) {this.name = name;}
  public String getName() {return name;}
  public static void m1(GFC301 r1, GFC301 r2) {
    r1.setName("Bird");
    r2 = r1;
  }
  public static void main (String[] args) {
    GFC301 pet1 = new GFC301("Dog");
    GFC301 pet2 = new GFC301("Cat");
    m1(pet1,pet2);
    System.out.println(pet1.getName() + "," + pet2.getName());
}}
What is the result of attempting to compile and run the program?
a.  Prints: Dog,Cat
b.  Prints: Dog,Bird
c.  Prints: Bird,Cat
d.  Prints: Bird,Bird
e.  Run-time error
f.  Compile-time error
h.None of the above

Question  5
public class MethodOver{
   public void setVar(int a, int b, float c){}
   }
}
  which overload the setVar? (Please choice three)
  A.private void setVar(int a, float c, int b){}
  B.protected void setVar(int a, int b, float c){}
  C.public int setVar(int a, float c, int b){return a;}
  D.public int setVar(int a, float c){return a;}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值