京巴
京巴 Dog
null
Dog京巴
第1题:
有如下程序:
include<iostream>
using namespace std;
class Pet{
char name[10];
public:
Pet(char*name){strcpy(this->name,name);}
const char*getName()const {return name;}
virtual void call()const=0;
};
class Dog:public Pet{
public:
Dog(char*name):Pet(name){}
void call()const{cout<<"汪汪叫":}
};
class Cat:public Pet{
public:
Cat(char*name):Pet(name){}
void call()const{cout<<"喵喵叫";}
};
int main(){
Pet*pet1=new Dog("哈克"),*pet2=new Cat("吉米");
cout<<pet1->getName();pet1->call();cout<<end1;
cout<<pet2->getName();pet2->call();cout<<end1;
return 0;
}
程序的输出结果是______。
第2题:
为使下列代码正常运行,应该在下画线处填入的选项是( )。 abstract class person{ public Person(String n){ name=n: } Public String getDescription; public String getName{ return name; } private string name; }
A.static
B.private
C.abstract
D.final
第3题:
public class Pet{ private String name; public Pet(String name){ this.name = name; } public void speak(){ System.out.print(name); } } public class Dog extends Pet{ public Dog(String name){ super(name); } public void speak(){ super.speak(); System.out.print(“ Dog ”); } } 执行代码 Pet pet = new Dog(“京巴”); pet.speak(); 后输出的内容是哪项?()
第4题:
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
第5题:
public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(){ System.out.print(4); } public Dog(String name){ //这里隐藏了一句代码:super.pet(); this(); System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
第6题:
Given the following code: 1) class Parent { 2) private String name; 3) public Parent(){} 4) } 5) public class Child extends Parent { 6) private String department; 7) public Child() {} 8) public String getValue(){ return name; } 9) public static void main(String arg[]) { 10) Parent p = new Parent(); 11) } 12) } Which line will cause error?()
第7题:
143
423
243
1134
第8题:
33
13
23
123
第9题:
23
13
123
321
第10题:
declare reset() using the synchronized keyword
declare getName() using the synchronized keyword
declare getCount() using the synchronized keyword
declare the constructor using the synchronized keyword
declare increment() using the synchronized keyword
第11题:
23
1 3
123
321
第12题:
smith,SALES
null,SALES
smith,null
null,null
第13题:
Java代码查错
1.
abstract class Name {
private String name;
public abstract boolean isStupidName(String name) {}
}
大侠们,这有何错误?
错。abstract method 必须以分号结尾,且不带花括号。
第14题:
public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(String name){ System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
第15题:
public class Employee{ private String name; public Employee(String name){ this.name = name; } public String getName(){ return name; } } public class Manager extends Employee{ public Manager(String name){ System.out.println(getName()); } } 执行语句new Manager(“smith”)后程序的输出是哪项?()
第16题:
public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(String name){ //这里隐藏了一句代码:super.pet(); System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
第17题:
public class Plant { private String name; public Plant(String name) { this.name = name; } public String getName() { return name; } } public class Tree extends Plant { public void growFruit() { } public void dropLeaves() { } } Which is true?()
第18题:
public class Pet{ private String name; public Pet(){ System.out.print(1); } public Pet(String name){ System.out.print(2); } } public class Dog extends Pet{ public Dog(){ System.out.print(4); } public Dog(String name){ this(); System.out.print(3); } } 执行new Dog(“棕熊”);后程序输出是哪项?()
第19题:
smith,SALES
null,SALES
smith,null
null,null
编译错误
第20题:
smith
null
SALES
编译错误
第21题:
smith
null
编译错误
name
第22题:
The code will compile without changes.
The code will compile if public Tree() { Plant(); } is added to the Tree class.
The code will compile if public Plant() { Tree(); } is added to the Plant class.
The code will compile if public Plant() { this(”fern”); } is added to the Plant class.
The code will compile if public Plant() { Plant(”fern”); } is added to the Plant class.
第23题:
京巴
京巴 Dog
null
Dog京巴
第24题:
smith
null
SALES
编译错误