单选题在Java语言中,如果你有下面的类定义:   abstract class Shape {  abstract void draw();    }    Class Square extends Shape {}  如果你试图编译上面的代码会发生()。A 一切成功编译B Shape可以编译,Square不能编译C Square可以编译,Shape不能编译D Shape,Square都不能编译

题目
单选题
在Java语言中,如果你有下面的类定义:   abstract class Shape {  abstract void draw();    }    Class Square extends Shape {}  如果你试图编译上面的代码会发生()。
A

一切成功编译

B

Shape可以编译,Square不能编译

C

Square可以编译,Shape不能编译

D

Shape,Square都不能编译


相似考题
更多“单选题在Java语言中,如果你有下面的类定义:   abstract class Shape {  abstract void draw();    }    Class Square extends Shape {}  如果你试图编译上面的代码会发生()。A 一切成功编译B Shape可以编译,Square不能编译C Square可以编译,Shape不能编译D Shape,Square都不能编译”相关问题
  • 第1题:

    下列程序片段中,能通过编译的是( )。 A.public abstract class Animal{ public void speak;}S

    下列程序片段中,能通过编译的是( )。

    A.public abstract class Animal{ public void speak;}

    B.public abstract class Animal{ public void speak{);}

    C.public class Animal{ pubilc abstract void speak;}

    D.public abstract class Animal{ pubile abstract void speak{};}


    正确答案:A
    A。【解析】Java中一个类是一个abstract类的子类,它必须具体实现父类的abstract方法。如果一个类中含有abstract方法,那么这个类必须用abstract来修饰(abstract类也可以没有abstract方法)。有abstract方法的父类只声明,由继承它的子类实现。所以选A。

  • 第2题:

    试题六(共15分)

    阅读以下说明、图和Java代码,填补Java代码中的空缺(1)~(6),将解答写在答题纸的

    对应栏内。

    【说明】

    已知对某几何图形绘制工具进行类建模的结果如图6.1所示,其中Shape为抽象(abstract)类,表示通用图形,Box(矩形)、Ellipse(椭圆)和Line(线条)继承(extends)了Shape类,其中,Circle表示圆(即特殊的椭圆)。

    下面的Java代码用于实现图 6-1所给出的设计思路,将其空缺处填充完整并编译运行,输出结果为:

    Ellipse

    Circle

    Ellipse

    C

    E

    【Java代码】

    (1) class Shape{

    public Shape(String name){

    this.name= name;

    }

    (2) void paint();

    String getName(){

    retum this.name;

    }

    final String name;

    };

    //Box 和Line类似下面 Ellipse,其代码略

    class Ellipse (3) {

    public Ellipse(String name){

    super(name);

    System.out.println("Ellipse");

    }

    Void paintO{∥绘制现状示意代码

    System.out.println(getName0);

    }

    };

    class Circle (4) {

    public Circle(String name){

    super(name);

    System.out.println("Circle");

    }

    };

    class Diagram{

    private Shape shapes[]= new Shape[2];

    public void drawAShape(Shape shape){

    shape.paint();

    }

    void erase A Shape(Shape shape){

    ∥删除形状,代码略

    }

    void drawShapes(){

    shapes*0+= new Circle("C”);

    shapes[l]= new Ellipse("E");

    for (int i=O; i<2;++i) {

    drawAShap(shapes[i]);//绘制形状

    }

    }

    void close(){

    for (int i=0;i<2; ++1) { []关闭图,删除所绘制图形

    (5) ;

    }

    }

    public static void main(String[] args){

    Diagram diagram= (6) ;

    diagram.drawShapes();

    diagram.close();

    }

    }


    正确答案:
    试题六参考答案(共 15分)
    (1) abstract 或public abstract (2 分)
    (2) abstract 或public abstract 或protected abstract (2 分)
    (3) extends Shape (2分)
    (4) extends Ellipse (3 分)
    (5) erase A Shape (shapes[i]) (3 分)
    (6) new Diagram() (3分)

  • 第3题:

    在Java语言中,如果你有下面的类定义:  Abstract class Shape{ Abstract void draw(); }  class Square extendeds Shape{} 如果你试图编译上面的代码会发生()。 

    • A、一切成功编译
    • B、Shape可以编译,Square不能编译
    • C、Square可以编译,Shape不能编译
    • D、Shape,Square都不能编译

    正确答案:B

  • 第4题:

    在Java语言中,如果你有下面的类定义:   abstract class Shape {  abstract void draw();    }    Class Square extends Shape {}  如果你试图编译上面的代码会发生()。 

    • A、一切成功编译
    • B、Shape可以编译,Square不能编译
    • C、Square可以编译,Shape不能编译
    • D、Shape,Square都不能编译

    正确答案:B

  • 第5题:

    public abstract class Shape {  int x;  int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  and a class Circle that extends and fully implements the Shape class. Which is correct?() 

    • A、 Shape s = new Shape(); s.setAnchor(10,10); s.draw();
    • B、 Circle c = new Shape(); c.setAnchor(10,10); c.draw();
    • C、 Shape s = new Circle(); s.setAnchor(10,10); s.draw();
    • D、 Shape s = new Circle(); s->setAnchor(10,10); s->draw();
    • E、 Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw();

    正确答案:C

  • 第6题:

    编译代码classMySstringextendsString{}会出现的情况是()

    • A、成功编译
    • B、不能编译,因为没有main方法
    • C、不能编译,因为String是abstract类型的
    • D、不能编译,因为String是final类型的

    正确答案:D

  • 第7题:

    1. interface I { void go(); }   2.   3. abstract class A implements I { }  4.   5. class C extends A {   6. void go(){ }   7. }   结果是什么?()  

    • A、代码通过编译
    • B、由于多个错误导致编译失败
    • C、由于第1行的错误导致编译失败
    • D、由于第6行的错误导致编译失败

    正确答案:D

  • 第8题:

    单选题
    在Java语言中,如果你有下面的类定义:abstractclassShape{ abstractvoiddraw();} ClassSquareextendsShape{} 如果你试图编译上面的代码会发生()。
    A

    一切成功编译

    B

    Shape可以编译,Square不能编译

    C

    Square可以编译,Shape不能编译

    D

    Shape,Square都不能编译


    正确答案: D
    解析: 暂无解析

  • 第9题:

    单选题
    编译代码classMySstringextendsString{}会出现的情况是()
    A

    成功编译

    B

    不能编译,因为没有main方法

    C

    不能编译,因为String是abstract类型的

    D

    不能编译,因为String是final类型的


    正确答案: D
    解析: 暂无解析

  • 第10题:

    单选题
    现有:  interface  I  {  void go();  }      abstract class A implements I { }      class C extends A  {     void go(){ }     }  结果是什么?()
    A

    代码通过编译

    B

    由于第1行的错误导致编译失败

    C

    由于笫3行的错误导致编译失败

    D

    由于第6行的错误导致编译失败


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    在Java语言中,如果你有下面的类定义:  Abstract class Shape{ Abstract void draw(); }  class Square extendeds Shape{} 如果你试图编译上面的代码会发生()。
    A

    一切成功编译

    B

    Shape可以编译,Square不能编译

    C

    Square可以编译,Shape不能编译

    D

    Shape,Square都不能编译


    正确答案: B
    解析: 暂无解析

  • 第12题:

    单选题
    给定如下Java程序片断:  class A{  public A (){   System.out.println("A");  } }  class B extends A{  public B(){  System.out.println("B"); }  public static void main(String[] args){    B b=new B();  } }  上述程序将()。
    A

    不能通过编译

    B

    通过编译,输出为:A B

    C

    通过编译,输出为:B

    D

    通过编译,输出为:A


    正确答案: B
    解析: 暂无解析

  • 第13题:

    编译以下代码,将出现什么情况?()

    abstract class Shape

    { abstract void draw();}

    Class Square extends Shape{ }

    A. Square类和Shape类都可以成功编译

    B. Square类无法编译,但Shape类可以编译

    C. 类无法编译,但Square类可以编译

    D. Square类和Shape类都无法编译


    正确答案:B

  • 第14题:

    以下语句可以通过编译: abstract class am_I_abstract { abstract void method1(); }。()

    此题为判断题(对,错)。


    答案:对

  • 第15题:

    在Java语言中,如果你有下面的类定义:abstractclassShape{ abstractvoiddraw();} ClassSquareextendsShape{} 如果你试图编译上面的代码会发生()。

    • A、一切成功编译
    • B、Shape可以编译,Square不能编译
    • C、Square可以编译,Shape不能编译
    • D、Shape,Square都不能编译

    正确答案:B

  • 第16题:

    给定如下Java程序片断:  class A{  public A (){   System.out.println("A");  } }  class B extends A{  public B(){  System.out.println("B"); }  public static void main(String[] args){    B b=new B();  } }  上述程序将()。 

    • A、不能通过编译
    • B、通过编译,输出为:A B
    • C、通过编译,输出为:B
    • D、通过编译,输出为:A

    正确答案:B

  • 第17题:

    现有:  interface  I  {  void go();  }      abstract class A implements I { }      class C extends A  {     void go(){ }     }  结果是什么?()   

    • A、代码通过编译
    • B、由于第1行的错误导致编译失败
    • C、由于笫3行的错误导致编译失败
    • D、由于第6行的错误导致编译失败

    正确答案:D

  • 第18题:

    你编译代码classMySstringextendsString{}会出现的情况是()

    • A、成功编译
    • B、不能编译,因为没有main方法
    • C、不能编译,因为String是abstract类型的
    • D、不能编译,因为String是final类型的

    正确答案:D

  • 第19题:

    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()

    • A、 public class Circle implements Shape { private int radius; }
    • B、 public abstract class Circle extends Shape { private int radius; }
    • C、 public class Circle extends Shape { private int radius; public void draw(); }
    • D、 public abstract class Circle implements Shape { private int radius; public void draw(); }
    • E、 public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
    • F、 public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }

    正确答案:B,E

  • 第20题:

    单选题
    在Java语言中,如果你有下面的类定义:   abstract class Shape {  abstract void draw();    }    Class Square extends Shape {}  如果你试图编译上面的代码会发生()。
    A

    一切成功编译

    B

    Shape可以编译,Square不能编译

    C

    Square可以编译,Shape不能编译

    D

    Shape,Square都不能编译


    正确答案: D
    解析: 暂无解析

  • 第21题:

    单选题
    1. interface I { void go(); }   2.   3. abstract class A implements I { }  4.   5. class C extends A {   6. void go(){ }   7. }   结果是什么?()
    A

    代码通过编译

    B

    由于多个错误导致编译失败

    C

    由于第1行的错误导致编译失败

    D

    由于第6行的错误导致编译失败


    正确答案: C
    解析: 暂无解析

  • 第22题:

    单选题
    public abstract class Shape {  int x;  int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  and a class Circle that extends and fully implements the Shape class. Which is correct?()
    A

     Shape s = new Shape(); s.setAnchor(10,10); s.draw();

    B

     Circle c = new Shape(); c.setAnchor(10,10); c.draw();

    C

     Shape s = new Circle(); s.setAnchor(10,10); s.draw();

    D

     Shape s = new Circle(); s->setAnchor(10,10); s->draw();

    E

     Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw();


    正确答案: A
    解析: 暂无解析

  • 第23题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


    正确答案: B,F
    解析: 暂无解析

  • 第24题:

    单选题
    你编译代码classMySstringextendsString{}会出现的情况是()
    A

    成功编译

    B

    不能编译,因为没有main方法

    C

    不能编译,因为String是abstract类型的

    D

    不能编译,因为String是final类型的


    正确答案: D
    解析: 暂无解析