A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© cflying 中级黑马   /  2015-7-25 21:14  /  491 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

9.下面程序的运行结果是(   c  )
public static void main(String[] args){
        StringBuffer sb = new StringBuffer();
        sb.append("qq").append("ww");
        show(sb,"ss");
        System.out.println(sb.length());
        }
            static void show(StringBuffer sb,String str){
          sb.append(str);
        }

a)        4
b)        2
c)        6
d)        0

11.        下面程序运行的结果是(    d )
  String str1= “1”, str2=”2”;
  if(str1==str2)
           System.out.println(“ABC”);
  else if(str1<str2)
           System.out.println(“DEF”);
  else
           System.out.println(“GHJ”);

a)        ABC
b)        DEF
c)        GHJ
d)        编译失败

12.        下面关于代码String str = new String(“abc”);描述正确的是(  b  )
a)        创建了一个字符串对象
b)        创建了两个对象,一个是new String(  )对象,一个是”abc”对象
c)        str.equals(“abc”);将返回true
d)        str.equals(“abc”);将返回false

33.        下面程序的运行结果是什么(a    )
  public static void main(String[] args){
                String s1 = “abc”;
                String s2 = “xyz”;
show(s1,s2);
System.out.println(s1+”-----”+s2);
}
static void show(String s1,String s2){
         s1 = s2+s1+”Q”; //xyzabcQ
    s2 = “W”+s1;  //WxyzabcQ
}
a)        abc-----xyz
b)        xyzabcQ-----xyzWabc
c)        xyzabcQ---- xyzabcQWabc
d)        xyzQ----Wabc


4.        编译运行如下Java代码,输出结果是(   )。
class Base {
        public void method(){
                System.out.print ("Base method");
        }
}
class Child extends Base{       
        public void methodB(){
                System.out.print ("Child methodB");
        }
}
class Sample {
        public static void main(String[] args) {
                Base base = new Child();
                base.methodB();    //编译时,看左边,发现Base类没有methodB方法,报错
        }
}
        A.        Base method
        B.        Child methodB       //
        C.        Base method Child MethodB
        D.        编译错误
6.        在Java接口中,下列选项中属于有效的方法声明是( A)。
        A.        public void aMethod();   
//接口中,方法默认声明格式:public abstract 返回类型  methodName()
              成员变量默认格式:public static final 类型 变量名;
        B.        final void aMethod();
        C.        void aMethod(){}
        D.        private void aMethod();

9.        给定如下Java代码 , 以下(  )方法可以加入Child类中。  
public class Parent{
int change(){
                //此处省略N行代码
}
}   
Class Child extends Parent{
//(此处可以放入下面哪个选项)  
}  
A.        public int change(){}  
B.        int show(int i){}  
C.        private int change(){}  
D.        abstract int change(){}

12.        给定两个java程序,如下:
public interface Face{   
int counter = 40;     
}      
public class Test implements Face{   
private static int counter;    //counter为自己私有成员变量,默认值0
public static void main(String[]args){
      System.out.println(++counter);         
}     
}   
Test.java 的编译运行结果是( )。  
A.        40  
B.        41  
C.        0  
D.        1

15.         给定java程序,如下:   
public class Test{
private static final int counter=10;  
public static void main(String [] args){         
System.out.println(++counter);  //final修饰的变量只能被赋值一次
}   
}
编译运行Test.java,结果是 ( )   
A.        10
B.        11  
C.        编译错误
D.        运行时出现异常

18.        程序Test.java编译运行后输出的结果是(   )。
public class Test {
    String s1="java";  
    public static void main(String args[]) {                  
        int z=2;              
        Test t=new Test();              
        System.out.println(t.s1+z);
    }  
}  
A.         java2     
B.        2     
C.        没有输出结果         
D.        java

22.        给出下面的不完整的类代码
  class Person {
    String name, department;
    int age;
    public Person(String n){ name = n; }
    public Person(String n, int a){ name = n; age = a; }
    public Person(String n, String d, int a) {
      // 完成Person(String n, int a)的逻辑
      department = d;
    }
  }
  下面的哪些表达式可以加到构造方法中的注释处? (   )
A. Person(n,a);   // 构造方法只能和new、this、super关键字使用,如果用方法名直接调用,会被当成成员方法调用,前面默认有this.关键字,而对象调自己的构造方法是不合理的。
B. this(Person(n,a));
C. this(n,a);
D. this(name,age);

24.        给定Java代码如下所示,则编译运行后,输出结果是( )。
class Parent {
Int money= 5000;
  public void count() {
    System.out.println(10%3);
  }
}
public class Child extends Parent{
  Int money= 10000;
  public void count() {
    System.out.println(10/3);
  }
  public static void main(String args[]) {
    Parent p = new Child();
p.count();
  }
}
        A.        1
        B.        1.0
        C.        3
        D.        3.3333333333333335
26.        查看下面代码:
class A {
public int i = 10;
   }
   class B extends A{
                   public int i = 20;
   }
public class Test{
           public static void main(String args[]){
              B b = new B();
               A a = b;    //多态
        System.out.println(b.i); //类型和实体都是子类 , 所以用子类自身的成员变量.
        System.out.println(a.i); //类型是父类型,实体是子类. 成员变量看的是左边的类型。
    }
}
输出为多少 ( )
   A.10 10   
   B.10 20     
   C.20 10   
   D.20 20

29.        给定如下一个Java源文件Child.java,编译并运行Child.java,以下结果正确的是( )。
class Parent1 {
    Parent1(String s){
        System.out.println(s);
    }
}
class Parent2  extends Parent1{
    Parent2(){
   //super();  
System.out.println("parent2");
    }
}
public class Child extends Parent2 {
    public static void main(String[] args) {
        Child child = new Child();
    }
}
        A.        编译错误:没有找到构造器Child()
        B.        编译错误:没有找到构造器Parent1()
        C.        正确运行,没有输出值
        D.        正确运行,输出结果为:parent2

31.        给定java代码,如下:  
public class Test{
static int i=0;
public int aMethod( ){
i++;
return i;
}
public static void main(String [] args){
Test test = new Test( );
test.aMethod( );  //i = 1
System.out.println(test.aMethod( )); //i =2
}
}编译运行后,输出结果是( )。
A.        0  
B.        1  
C.        2  
D.        3
33.        给出下面的代码
  class Person {
    String name,department;
    public void printValue(){
      System.out.println("name is "+name);
      System.out.println("department is "+department);
    }
  }
  public class Teacher extends Person {
    int salary;
    public void printValue(){
      // 完成父类代码中printValue()相同的工作
      System.out.println("salary is "+salary);
    }
  }
  下面的哪些表达式可以加入printValue()方法的注释部分?
A. printValue();
B. this.printValue();
C. person.printValue();
D. super.printValue()

35.        在java中,以下程序的输出结果是(  )
class Point  {     
int x;
        boolean y;     
void output()     {
               System.out.println(x);        
System.out.println(y);      
}
            public static void main(String[] args)     {
                Point pt =new Point();        
        pt.output();   
}  
}
A.        运行错误
B.        0 ture  
C.  0 false
D.        0 0
38.        分析如下Java代码,如果想在控制台上输出“B类的test()方法”,则在主函数应填入( )。
class A {
    public void test() {
        System.out.println("A类的test()方法");
    }
}
class B extends A {
    public void test() {
        System.out.println("B类的test()方法");
    }
    public static void main(String args[]) {
                                          
    }
}
        A.        A a = new B();
                    a.test();
        B.        A a = new A();
                    a.test();
        C.        B b = new A();
                    b.test();
        D.        new B().test();

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马