• 2022-05-31
    从下面四段(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; } }
  • C

    举一反三

    内容

    • 0

      抽象类A和抽象类Test的定义如下: abstract class A { abstract int getInfo() { } } public class Test extends A { private int a = 0; public int getInfo() { return a; } public static void main(String args[]) { Test b= new Test(); System.out.println(b.getInfo()); } } 关于上述代码说明正确的是_________

    • 1

      【填空题】public class ThisTest{ private String name; private int age; public ThisTest() { System.out.println("产生一个新的Person对象。"); } public ThisTest (String name, int age) { this(); this.name = name; this.age = age; } public String getInf() { return "姓名:" + name + ",年龄:" + age; } public static void main(String[] args) { ThisTest per = new ThisTest("张三", 20); System.out.println(per.getInf()); } } 运行结果为:____

    • 2

      在以下代码中,( )是类Teacher的方法。 public class Teacher { int age=33; private string name; public string Name { get{return name;} set{name=value;} } public void SaySomething(){ //….. } }

    • 3

      给定代码如下: public abstract interface Frobnicate { public void twiddle(String s); } 以下哪个类是正确的?(). A: public abstract class Frob implements Frobnicate { public abstract void twiddle(String s) { } } B: public abstract class Frob implements Frobnicate { } C: public class Frob extends Frobnicate { public void twiddle(Integer i) { } } D: public class Frob implements Frobnicate { public void twiddle(Integer i) { } }

    • 4

      请填写代码 public class Teacher { int age=33; private string name; public string Name { get{请在此处填上代码} set{请在此处填上代码} } } public void SaySomething{ //….. }