⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3.txt

📁 关于java的10个例子如(vector插入,删除),希望大家喜欢.
💻 TXT
字号:
1、给出下列程序,正确的输出是?(选1个答案)
class A {
public void a(int i) { System.out.println(i); }
public void a(double d) { System.out.println(d); }
public static void main(String[] args) {
    new A().a(5.0f);
}
}
a)	编译错误
b)	编译正确,输出5.0
c)	编译正确,输出5

2、下列叙述哪些是正确的?(选1个答案)
a) 接口可以有构造器       
b) 抽象类可以有构造器      
c) 接口引用不可以使用instanceof进行对象是否实现接口的判断

3、	给出下列程序,输出结果是?(选1个答案)
public class Card {  int x;
    public static void main(String[] args) {
        Card c1 = new Card();  c1.x = 5;
        Card c2 = new Card();  c2.x = 6;
        swap(c1, c2);    System.out.println(c1.x + "" + c2.x);
    }
    static private void swap(Card c1, Card c2) 
    { Card temp = c1; c1 = c2; c2 = temp; }   }
a) 该程序有语法错误,编译失败
b) 编译成功, 运行成功,输出结果是65
c) 编译成功, 运行成功,输出结果是56
d) 以上答案都不对

4、给定下列程序,文件名为A.java,正确的叙述是?(选2个答案)
public class A { int x;     public A(int x) { this.x = x; } }
public class B{ int y;   public B(int y) { super(this.y); }}
a) 编译成功			        b) 编译失败,提示构造器A()不存在
c) 编译失败,super(this.y)调用错误		    d) 编译失败,B 为public 类有问题。



5、有关类Demo,哪句描述是正确的?  (选1个答案)
  public class Demo extends Base{ 
  private int count; 
  public Demo(){ 
   System.out.println("A Demo object has been created"); 
  } 
  protected void addOne() {count++; } 
  } 

 A 当创建一个Demo类的实例对象时,count的值为0。 

 B 当创建一个Demo类的实例对象时,count的值是不确定的。 

 C 超类对象中可以包含改变count 值的方法。 

 D Demo的子类对象可以访问count。 

6、当编译和运行下列程序段时,会发生什么? (选1个答案)
  class Base {} 
  class Sub extends Base {} 
  class Sub2 extends Base {} 
  public class CEx{ 
   public static void main(String argv[]){ 
   Base b = new Base(); 
   Sub s = (Sub) b; 
   } 
  } 

 A 通过编译和并正常运行。 

 B 编译时出现例外。 

 C 编译通过,运行时出现例外。 

7、如果任何包中的子类都能访问超类中的成员,那么应使用哪个限定词? (选1个答案)

 A friendly 

 B private 

 C protected 

 D transient 

8、下面的哪个选项是正确的? 
  class ExSuper{ 
   String name; 
   String nick_name; 
   public ExSuper(String s,String t){ 
    name = s;
    nick_name = t; 
   } 
    public String toString(){ 
     return name; 
    } 
   } 
   public class Example extends ExSuper{ 
    public Example(String s,String t){ 
    super(s,t); 
    } 
    public String toString(){ 
     return name +"a.k.a"+nick_name;
    } 
    public static void main(String args[]){
     ExSuper a = new ExSuper("First","1st");
     ExSuper b = new Example("Second","2nd");
     System.out.println("a is"+a.toString());
     System.out.println("b is"+b.toString());
    }
  }


 A 编译时会出现例外。 

 B 运行结果为:
        a is First
        b is second



 C 运行结果为:
        a is First
        b is Secong a.k.a 2nd


 D 运行结果为:
        a is First a.k.a 1nd
        b is Second a.k.a 2nd

9、运行下列程序的结果是哪个?
  abstract class MineBase {
   abstract void amethod(); 
   static int i;
   } 

  public class Mine extends MineBase
  {
   public static void main(String argv[]){
    int[] ar = new int[5];
    for(i = 0;i < ar.length;i++)
    System.out.println(ar[i]);
   }
  }


 A 打印5个0。 

 B 编译出错,数组ar[]必须初始化。 

 C 编译出错, Mine应声明为abstract。 

 D 出现IndexOutOfBoundes的例外。


   


10、下面哪个语句是正确的? 

 A Object o = new Button("A"); 

 B Button b=new Object("B"); 

 C Panel p = new Frame(); 

 D Frame f = new Panel(); 

 E Panel p = new Panel(); 

11、指出下列程序的所有错误? 
  final class First {
   private int a = 1;
   int b = 2;
  } 

  class Second extends First {
   public void method() {
    System.out.println(a + b);
   }
  }


 A println()参数应为字符串,因此此处不能调用该方法。 

 B 因为变量a 是private ,所以在其他类中不能访问a。 

 C Second 不能继承First。 

 D 关键字final不能修饰类。 

12、接口A的定义如下,指出下列哪些类实现了该接口? 
  interface A { 
   int method1(int i); 
   int method2(int j); 
  } 

 A class B implements A { 
    int method1() { } 
    int method2() { 
    } 
   } 

 B class B { 
    int method1(int i) { } 
    int method2(int j) { } 
   } 

 C class B implements A { 
   public int method1(int i) { } 
   public int method2(int j) { } 
   } 

 D class B extends A { 
    int method1(int i) { } 
    int method2(int j) { } 
   } 

 E class B implements A { 
   public int method2(int j) { } 
   public int method1(int i) { } 
   } 


13、给出下面程序,正确的叙述是?(选1个答案)
	class A {
         static void a() { System.out.println("a"); }
    }
    class B extends A {
        static void a() { System.out.println("b"); }
        public static void main(String[] args) {
            A x = new B();
            x.a();
        }
    }
    a) 编译失败
    b) 编译成功,输出a
    c) 编译成功,输出b
    d) 以上答案都不对
    
14、给定下列程序,分别在两个文件,正确的叙述是?(选1个答案)
//filename is A.java, 这是第一个文件
package com.abc.e1;
abstract public class A {
    protected abstract void a();
    protected void b() { this.a(); }
}
//filename is B.java,第二个文件
package com.abc.e2;
public class B extends A {
    public void a() { System.out.println("hello"); }
    public void c() { this.b(); }
}
a) 编译失败,因为子类不能访问父类的protected方法
b) 编译失败,B类中不能使用this.b(),应改为super.b()
c) 编译失败,abstract应放在public之后
d) 编译失败,子类的覆盖方法的访问权限不正确
e) 以上答案都不对

15、给出下列程序,正确的叙述是?(选1个答案)
interface K { void a(); }
interface M { 
	static public final int PORT = 2222;
	public void b();
}
class A implements K, M {
	void a() { System.out.println(PORT); }
	public void b() { a(); }
}
a)	编译正确
b)	编译失败, PORT定义错误
c)	编译失败,A类不能实现两个接口
d)	编译失败,A类中a方法定义访问权限不正确

16、给出如下程序,正确的叙述是?(选1个答案)
class Outer { 
    int i = 5;
    private static class Inner {
        void a() { System.out.println(i); }
    }
}
a) 编译正确
b) 编译失败,内部类不能被定义成私有的成员
c) 编译失败,内部类不能被定义成静态的成员
d) 编译失败,静态内部类不能访问外部实例成员




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -