编译以下代码,将出现什么情况?()abstract class Shape{ abstract void draw();}Class Square extends Shape{ }A. Square类和Shape类都可以成功编译B. Square类无法编译,但Shape类可以编译C. 类无法编译,但Square类可以编译D. Square类和Shape类都无法编译
编译以下代码,将出现什么情况?()
abstract class Shape
{ abstract void draw();}
Class Square extends Shape{ }
A. Square类和Shape类都可以成功编译
B. Square类无法编译,但Shape类可以编译
C. 类无法编译,但Square类可以编译
D. Square类和Shape类都无法编译
相关考题:
下列程序片段中,能通过编译的是A.public abstract class Animal{ public void speak();}B.public abstract class Animal{ public void speak(){}}C.public class Animal{ public abstract void speak();}D.public abstract class Animal{ public abstract void speak(){}}
Given:10. interface Data { public void load(); }11. abstract class Info { public abstract void load(); }Which class correctly uses the Data interface and Info class?()() A.B.C.D.E.F.
运行下列程序的结果是 ( ) 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个0B.编译出错,数组ar[]必须初始化C.编译出错,Mine应声明为abstractD.出现IndexOutOfBoundes的例外
Java代码查错1.abstract class Name {private String name;public abstract boolean isStupidName(String name) {}}大侠们,这有何错误?
下面的代码中有什么错误吗?_______using System;class A{public virtual void F(){Console.WriteLine("A.F");}}abstract class B:A{public abstract override void F();
下列程序片段中,能通过编译的是( )。 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{};}
试题六(共15分)阅读以下说明、图和Java代码,填补Java代码中的空缺(1)~(6),将解答写在答题纸的对应栏内。【说明】已知对某几何图形绘制工具进行类建模的结果如图6.1所示,其中Shape为抽象(abstract)类,表示通用图形,Box(矩形)、Ellipse(椭圆)和Line(线条)继承(extends)了Shape类,其中,Circle表示圆(即特殊的椭圆)。下面的Java代码用于实现图 6-1所给出的设计思路,将其空缺处填充完整并编译运行,输出结果为:EllipseCircleEllipseCE【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; i2;++i) {drawAShap(shapes[i]);//绘制形状}}void close(){for (int i=0;i2; ++1) { []关闭图,删除所绘制图形(5) ;}}public static void main(String[] args){Diagram diagram= (6) ;diagram.drawShapes();diagram.close();}}
以下程序的编译和运行结果为?abstract class Base{abstract public void myfunc();public void another(){System.out.println("Another method");}}public class Abs extends Base{public static void main(String argv[]){Abs a = new Abs();A.amethod();}public void myfunc(){System.out.println("My Func");}public void amethod(){myfunc();}}A.输出结果为 My FuncB.编译指示 Base 类中无抽象方法C.编译通过,但运行时指示Base 类中无抽象方法D.编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。
以下语句能顺利通过编译: abstract class class1 { } public class mainClass { public static void main(String args[]) { class1 cs1=new class1(); } } 。() 此题为判断题(对,错)。
设有程序如下: abstract class absclass { abstract void method1(); } class conclass extends absclass { public void method1() { System.out.println("子类");} } public class mainclass { public static void main(String args[]) { absclass ac1=new absclass(); //语句1 absclass ac2=new conclass(); //语句2 ac2.method1(); //语句3 } } 则main()方法中的第一条语句(即语句1)可以顺利通过编译。()此题为判断题(对,错)。
阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。【说明】以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。【Java代码】interface?DrawCircle?{? //绘制圆形 public(1) ;}class?RedCircle?implements?DrawCircle?{? ?//绘制红色圆形???????public?void?drawCircle(int?radius,intx,?int?y)??{????????????System.out.println("Drawing?Circle[red,radius:"?+?radius?+",x:"?+?x?+?",y:"?+y+?"]");???????}}class?GreenCircle?implements?DrawCircle?{????//绘制绿色圆形??????public?void?drawCircle(int?radius,?int?x,int?y)?{???????????System.out.println("Drawing?Circle[green,radius:"?+radius+",x:?"?+x+?",y:?"?+y+?"]");??????}}abstract?class?Shape?{????//形状? protected? ? (2)???;? ? public?Shape(DrawCircle?drawCircle)?{? ?this.drawCircle=?drawCircle;? ? ? public?abstract?void?draw();}class?Circle?extends?Shape?{? //圆形? ?private?int?x,y,radius;? public?Circle(int?x,int?y,intradius,DrawCircle?drawCircle)?{? ?(3)???;? this.x?=?x;? ? ? this.y?=?y;? ?this.radius?=radius;? }? ? ?public?void?draw()?{? ? drawCircle.? ?(4)? ?;? ? ? }}public?class?DrawCircleMain?{? public?static?void?main(String[]?args)?{? Shape?redCircle=new?Circle(?100,100,10,? (5) );//绘制红色圆形? Shape?greenCircle=new?Circle(200,200,10,(6) );//绘制绿色圆形? ?redCircle.draw(); greenCircle.draw();? ?}}
在Java语言中,如果你有下面的类定义: Abstract class Shape{ Abstract void draw(); } class Square extendeds Shape{} 如果你试图编译上面的代码会发生()。 A、一切成功编译B、Shape可以编译,Square不能编译C、Square可以编译,Shape不能编译D、Shape,Square都不能编译
Which declaration prevents creating a subclass of an outer class?()A、 Static class FooBar{}B、 Private class FooBar{}C、 Abstract public class FooBar{}D、 Final public class FooBar{}E、 Final abstract class FooBar{}
现有: interface I { void go(); } abstract class A implements I { } class C extends A { void go(){ } } 结果是什么?() A、代码通过编译B、由于第1行的错误导致编译失败C、由于笫3行的错误导致编译失败D、由于第6行的错误导致编译失败
下列哪个类的声明是正确的()A、abstract final class HI{}B、abstract private move(){}C、protected private number;D、public abstract class Car{}
下列是抽象类的声明的是()A、 abstract class figure{ }B、 class abstract figure{ }C、 seald class figure{ }D、 static class figure{ }
单选题Which declaration prevents creating a subclass of an outer class?()A Static class FooBar{}B Private class FooBar{}C Abstract public class FooBar{}D Final public class FooBar{}E Final abstract class FooBar{}
单选题在Java语言中,如果你有下面的类定义: abstract class Shape { abstract void draw(); } Class Square extends Shape {} 如果你试图编译上面的代码会发生()。A一切成功编译BShape可以编译,Square不能编译CSquare可以编译,Shape不能编译DShape,Square都不能编译
单选题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行的错误导致编译失败
单选题现有: interface I { void go(); } abstract class A implements I { } class C extends A { void go(){ } } 结果是什么?()A代码通过编译B由于第1行的错误导致编译失败C由于笫3行的错误导致编译失败D由于第6行的错误导致编译失败
多选题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?()Apublic class Circle implements Shape { private int radius; }Bpublic abstract class Circle extends Shape { private int radius; }Cpublic class Circle extends Shape { private int radius; public void draw(); }Dpublic abstract class Circle implements Shape { private int radius; public void draw(); }Epublic class Circle extends Shape { private int radius;public void draw() {/* code here */} }Fpublic abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
单选题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();
单选题现有: 1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat extends Feline { 8. public void eat() { } 9. } 和五个声明: abstract class Feline implements Animal { } abstract class Feline implements Animal { void eat(); } abstract class Feline implements Animal { public void eat(); } abstract class Feline implements Animal { public void eat() { } } abstract class Feline implements Animal { abstract public void eat(); } 分别插入到第5行,有几个可以通过编译?()A0B1C2D3
多选题abstract class A { abstract void al(); void a2() { } } class B extends A { void a1() { } void a2() { } } class C extends B { void c1() { } } and: A x = new B(); C y = new C(); A z = new C(); Which four are valid examples of polymorphic method calls?()Ax.a2();Bz.a2();Cz.c1();Dz.a1();Ey.c1();Fx.a1();
单选题现有: interface Animal { void eat () ; } //insert code here public class HouseCat extends Feline { public void eat() { } } 和五个申明 abstract class Feline implements Animal { } abstract class Feline implements Animal { void eat () ; } abstract class Feline implements Animal { public void eat();} abstract class Feline implements Animal { public void eat() {} } abstract class Feline implements Animal { abstract public void eat();} 结果为:()A1B2C3D4