class NumTest{ final int id = 1; int id2 = 1; NumTest(int id,int id2){ this.id = id; this.id2 = id2; } void printId(){ System.out.print(id+id2+" "); } public static void main(String[] args) { NumTest a = new NumTest(1,2); NumTest b = new NumTest(2,1); NumTest c = new NumTest(0,0); a.printId(); b.printId(); c.printId(); }}
A: 3 3 0
B: 1 2 0
C: 2 1 0
D: 编译报错
A: 3 3 0
B: 1 2 0
C: 2 1 0
D: 编译报错
举一反三
- 中国大学MOOC: class NumTest{ final int id = 1; int id2 = 1; NumTest(int id,int id2){ this.id = id; this.id2 = id2; } void printId(){ System.out.print(id+id2+ ); } public static void main(String[] args) { NumTest a = new NumTest(1,2); NumTest b = new NumTest(2,1); NumTest c = new NumTest(0,0); a.printId(); b.printId(); c.printId(); }}
- Use the following code to answer the following questions: int id = 0; cout [< "ID: "; cin ]> id; if (id == 1) cout << "Janet"; else if (id == 2 || id == 3) cout << "Mark"; else if (id == 4) cout << "Jerry"; else cout << "Sue"; (1) The above code display ____when the id variable contains the number 2? (2) The above code display ____when the id variable contains the number 4? (3) The above code display ____when the id variable contains the number 3? (4) The above code display ____when the id variable contains the number 8
- 已知 x = [1, 2, 1],那么表达式 id(x[0]) == id(x[2]) 的值为_______________。
- 有如下程序: #include<iostream> using namespace std; class Con char ID; public: Con():ID(’A)cout<<1; Con(char ID):ID(ID)cout<<2; Con(Con &c):ID(c.getID())cout<<3; char getID()constreturn ID; ; void show(Con c)cout<<c.getID(); int main() Con c1; show(c1); Con c2(’B’); show(c2); return 0; 执行上面程序的输出是( )。 A: 13A23A B: 23A13B C: 13A23B D: 13823A
- 在下列查询条件中,可以使用索引的是( )。 A: id + 2 > 3 B: id > 3 - 2 C: id + 1 = 3 D: id = 3