以下的类(接口)定义中正确的是( )
A: public class A{ private int x; public getX(){ return x; }}
B: public abstract class A{ private int x; public abstract int getX(); public int aMethod(){ return 0; }}
C: public class A{ private int x; public abstract int getX();}
D: public interface interfaceA{ private int x; public int getX(){ return x; }}
A: public class A{ private int x; public getX(){ return x; }}
B: public abstract class A{ private int x; public abstract int getX(); public int aMethod(){ return 0; }}
C: public class A{ private int x; public abstract int getX();}
D: public interface interfaceA{ private int x; public int getX(){ return x; }}
举一反三
- (7-1)请阅读程序,并写出程序运行结果。 class X{ int getX() { return 5; } } class Y extends X{ int getX() { return 6; } } class T extends X{ int getX() { return 7; } } public class Demo10 { public static void main(String[] args) { X x=new X(); Y y=new Y(); X t=new T(); int sum=x.getX()+y.getX()+t.getX(); System.out.println(sum); } }
- 有如下程序: #include<iostream> using namespace std; class XX{ int x; public: XX(int XX=0):x(xx){} int getX(){return x;} }; class YY:public XX{ int y; public: YY(int xx,int yy):XX(xx),y(yy){} int getV(){return getX()+y;} }; int main(){ YY c(3,4); cout<<c.getV()+c.getX()<<endl; return 0; } 运行这个程序的输出结果是______。 A: 3 B: 4 C: 7 D: 10
- 从下面四段代码中选择出正确的代码段() A: public class Something {public static void main(String[] args) {Other o = new Other();new Something().addOne(o);}public void addOne(final Other o) {o.i++;}}class Other {public int i;} B: public class Something {void doSomething () {private String s = ̶”;int l = s.length();}} C: abstract class Name {private String name;public abstract boolean isStupidName(String name) {}} D: public class Something {public int addOne(final int x) {return ++x; }}
- 分析程序,将代码补充完整class A { private int x; public A(int i) { x = i; } } class B extends A { private int y; public B(int i) { ___________ ____; y = i; } }
- 从下面四段(A,B,C,D)代码中选择出正确的代码段 A: abstract class Name { private String name; public abstract boolean isStupidName(String name) {} } B: public class Something { void doSomething () { private String s = ""; int l = s.length(); } } C: public class Something { public static void main(String[] args) { Other o = new Other(); new Something().addOne(o); } public void addOne(final Other o) { o.i++; } } class Other { public int i; } D: public class Something { public int addOne(final int x) { return ++x; } }