从下面四段代码中选择出正确的代码段()
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; }}
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; }}
举一反三
- 从下面四段(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; } }
- 智慧职教: 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; }
- 分析下面的程序,输出的结果是? public class Test { public static void main(String[] args) { final Person p = new Person("张三", 23); p.setName("李四"); p.setAge(24); System.out.println(p); } } class Person { private String name; private int age; public Person() { super(); } public Person(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "我的姓名是:" + name + ",我的年龄是:" + age ; } }
- 读代码: public class Test { public static void main (String args[]) { class Foo { public int i = 3; } Object o = (Object) new Foo(); Foo foo = (Foo)o; System.out.println(foo.i); } } 结果是:
- (06-06)分析如下所示的Java代码,其中this关键字的意思是( )。 public class Test { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; //this关键字所在的行 } } Class Main{ Public static void main(String []args){ Test T1 = new Test(); T1.setname(“zhangsan”); } }