网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
单选题
20. public float getSalary(Employee e) { 21. assert validEmployee(e); 22. float sal = lookupSalary(e); 23. assert (sal>0); 24. return sal; 25. } 26. private int getAge(Employee e) { 27. assert validEmployee(e); 28. int age = lookupAge(e); 29. assert (age>0); 30. return age; 31. } Which line is a violation of appropriate use of the assertion mechanism?()
A
line 21
B
line 23
C
line 27
D
line 29
参考答案
参考解析
解析:
暂无解析
更多 “单选题20. public float getSalary(Employee e) { 21. assert validEmployee(e); 22. float sal = lookupSalary(e); 23. assert (sal0); 24. return sal; 25. } 26. private int getAge(Employee e) { 27. assert validEmployee(e); 28. int age = lookupAge(e); 29. assert (age0); 30. return age; 31. } Which line is a violation of appropriate use of the assertion mechanism?()A line 21B line 23C line 27D line 29” 相关考题
考题
●试题五阅读下列程序说明,将应填入(n)处的字句写在答卷纸的对应栏内。【程序说明】对于一个公司的雇员来说,无非有3种:普通雇员、管理人员和主管。这些雇员有共同的数据:名字、每小时的工资,也有一些共同的操作:数据成员初始化、读雇员的数据成员及计算雇员的工资。但是,他们也有不同。例如,管理人员除有这些共同的特征外,有可能付固定薪水,主管除有管理人员的共同特征外,还有其他物质奖励等。3种雇员中,管理人员可以看作普通雇员的一种,而主管又可以看作管理人员的一种。我们很容易想到使用类继承来实现这个问题:普通雇员作为基类,管理人员类从普通雇员类中派生,而主管人员类又从管理人员类中派生。下面的程序1完成上述各个类的定义,并建立了3个雇员(一个普通雇员、一个管理人员和一个主管)的档案,并打印出各自的工资表。将"程序1"中的成员函数定义为内联函数,pay成员函数定义为虚函数,重新完成上述要求。【程序1】//普通雇员类class Employee{public:Employee(char*theName,float thePayRate);char*getName()const;float getPayRate()const;float pay(float hoursWorked)const;protected:char*name;//雇员名称float payRate;//薪水等级};Employee::Employee(char*theName,float thePayRate){name=theName;payRate=thePayRate;}char*Employee::getName() const{return name;}float Employee::getPayRate()const{return payRate;}float Employee::pay(float hoursWorked)const{return hoursWorked*payRate;}//管理人员类class Manager∶public Employee{public://isSalaried付薪方式:true付薪固定工资,false按小时付薪Manager(char*theName,float thePayRate,bool isSalaried);bool getSalaried()const;float pay(float hoursWorked)const;protected:bool salaried;};Manager::Manager(char*theName,float thePayRate,bool isSalaried)∶Employee(theName,thePayRate){salaried=isSalaried;}bool Manager::getSalaried() const{return salaried;}float Manager::pay(float hoursWorked)const{if(salaried)return payRate;/*else*/return Employee::pay(hoursWorked);}//主管人员类class Supervisor:public Employee{public:Supervisor(char*theName,float thePayRate,float theBouns):Employee(theName,thePayRate, (1) ),bouns(theBouns){}float getBouns()const{return bouns;}float pay(float hoursWorked)constreturn (2) ;}protected:float bouns;}#include"iostream.h"void main(){Employee e("Jack",50.00);Manager m("Tom",8000.00,true);Supervior s("Tanya",8000.00,8000.00);cout"Name:"e.getName()endl;cout"Pay:"e.pay(80)endl;//设每月工作80小时cout"Name:"m.getName()endl;cout"Pay:"m.pay (40) endl;cout"Name:"s.getName()endl;cout"Pay:"s.pay (40) endl;//参数40在这里不起作用}【程序2】#include"employee.h"//普通雇员类class Employee{public://构造函数Employee(string theName,float thePayRate):name(theName),payRate(thePayRate){}//取雇员姓名string getName() const{returnname;}//取雇员薪水等级float getPayRate()const{return payRate;}//计算雇员薪水virtual float pay(float hoursWorked)const{return (3) ;}protected:string name;//雇员名称float payRate;//薪水等级};//管理人员类//继承普通雇员类class Manager:public Employee{public://构造函数//isSalaried标识管理人员类的付薪方式//true 按阶段付薪(固定工资)//false按小时付薪Manager(string theName,float thePayRate,bool isSalaried):Employee(theName,thePayRate),salaried(isSalaried){}//取付薪方式bool getSalaried()const{return salaried;}//计算薪水virtual float pay(float (4) )const;protected:bool salaried;};float Manager::pay(float hoursWorked)const{if(salaried)//固定付薪方式return payRate;else//按小时付薪return (5) ; }//主管人员类class Supervisor: (6){public://构造函数Supervisor(string theName,float thePayRate,float theBouns):Manager(theName,thePayRate,true),bouns(theBouns){}//取奖金数额float getBouns()const{return bouns;}//计算薪水virtual float pay(float hoursWorked)const{retum payRate+bouns;}(7)float bouns;}#include"employee.h"#include"iostream.h"void main(){(8) *ep[3];ep[0]=new Employee("Jack","50.00");ep[1]=new Manager("Tom","8000.00",true);ep[2]=new Supervior("Tanya","8000.00","8000.00");for(int i=0;i3;i++){cout"Name:" (9) endl;cout"Pay:" (10) endl;//设每月工作80小时}}
考题
类Test定义如下,将下列______方法插入③行处是不合法的。 ( )①public class Test{②public float Method(float a,float b){}③④}A.public float Method(float a,float b,float c){}B.public float Method(float c,float d){}C.public int Method(int a,int b){}D.private float Method(int a,int b,int c){}
考题
阅读和理解下面程序段: class Manager extends Employee{ public Manager(String n,double s,int year,int month,int day){ super(n,s,year,month,day); bonus=0; } public double getSalary(){ double baseSalary-super.gerSalary(); return baseSalary+bonus; } public void setBonus(double b){bonus=b; ) private double bonus; } Manager是Employee的子类,其理由是( )。A.Manager的适用范围较宽B.extends关键字声明C.Manager的域减小了D.雇员是一个经理
考题
类Test定义如下,将下列( )方法插入③行处是不合法的。 ①publicClass Test{ ②public float Method(floatA,float b){} ③ ④}A.public float Method(floatA,float b,floatC){}B.public float Method(noatC,float d) {}C.public int Method(intA,int b){}D.private float Method(intA,int b,intC){}
考题
类testl定义如下: public class test1 { public float amethod(float a,float b){ } }A.public foat amethod(float a,float b,foat c){ }B.public float amethod(float c,float d){ }C.public int amethod(int a,int b){ }D.private float amethod(int a,int b,int c){ }
考题
类Test定义如下,将下列哪个方法插入③行处是不合法的( )?① public class Test{② public float Method(float a,float B) { }③ ______④ }A.public float Method(float a,float b,float C) { }B.public float Method(float c,float d){ }C.public int Method(int a,int B) { }private float Method(int a,int b,int C) { }D.private float Method(int a,int b,int C) { }
考题
10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14. } And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine?() A、 StackOverflowErrorB、 NullPointerExceptionC、 NumberFormatExceptionD、 IllegalArgumentExceptionE、 ExceptionlnlnitializerError
考题
public class MethodOver { public void setVar (int a, int b, float c) { } } Which two overload the setVar method?()A、 Private void setVar (int a, float c, int b) {}B、 Protected void setVar (int a, int b, float c) {}C、 Public int setVar (int a, float c, int b) (return a;)D、 Public int setVar (int a, int b, float c) (return a;)E、 Protected float setVar (int a, int b, float c) (return c;)
考题
interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?() A、 public class Employee extends Info implements Data { public void load() { /*do something*/ } }B、 public class Employee implements Info extends Data { public void load() { /*do something*/ } }C、 public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D、 public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E、 public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F、 public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
考题
类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ return 0;} 3. 4.} 将以下哪种方法插入行3是不合法的。()A、public float aMethod(float a, float b,float c){ return 0;}B、public float aMethod(float c,float d){ return 0;}C、public int aMethod(int a, int b){ return 0;}D、private float aMethod(int a,int b,int c){ return 0;}
考题
20. public float getSalary(Employee e) { 21. assert validEmployee(e); 22. float sal = lookupSalary(e); 23. assert (sal0); 24. return sal; 25. } 26. private int getAge(Employee e) { 27. assert validEmployee(e); 28. int age = lookupAge(e); 29. assert (age0); 30. return age; 31. } Which line is a violation of appropriate use of the assertion mechanism?() A、 line 21B、 line 23C、 line 27D、 line 29
考题
11. public class Test { 12. public void foo() { 13. assert false; 14. assert false; 15. } 16. public void bar(){ 17. while(true){ 18. assert false; 19. } 20. assert false; 21. } 22. } What causes compilation to fail?() A、 Line 13B、 Line 14C、 Line 18D、 Line 20
考题
public class Test{ public static void main( String[] argv ){ // insert statement here } } Which statement, inserted at line 3, produces the following output?() Exception in thread “main” java.lang.AssertionError: true at Test.main(Test.java:3) A、 assert true;B、 assert false;C、 assert false : true;D、 assert false == true;E、 assert false: false;
考题
public class MethodOver { private int x, y; private float z; public void setVar(int a, int b, float c){ x = a; y = b; z = c; } } Which two overload the setVar method?()A、 void setVar (int a, int b, float c){ x = a; y = b; z = c; }B、 public void setVar(int a, float c, int b) { setVar(a, b, c); }C、 public void setVar(int a, float c, int b) { this(a, b, c); }D、 public void setVar(int a, float b){ x = a; z = b; }E、 public void setVar(int ax, int by, float cz) { x = ax; y = by; z = cz; }
考题
Which two demonstrate an “is a” relationship?() A、 public interface Person { } public class Employee extends Person { }B、 public interface Shape { } public class Employee extends Shape { }C、 public interface Color { } public class Employee extends Color { }D、 public class Species { } public class Animal (private Species species;)E、 interface Component { } Class Container implements Component ( Private Component[ ]children; )
考题
11. class Person { 12. String name = “No name‟; 13. public Person(String nm) { name = nm; } 14. } 15. 16. class Employee extends Person { 17. String emplD = “0000”; 18. public Employee(String id) { empID = id; } 19. } 20. 21. public class EmployeeTest { 22. public static void main(String[] args) { 23. Employee e = new Employee(”4321”); 24. System.out.println(e.empID); 25. } 26. } What is the result?() A、 4321B、 0000C、 An exception is thrown at runtime.D、 Compilation fails because of an error in line 18.
考题
11. public void someMethod(Object value) { 12. // check for null value .... 20. System.out.println(value.getClass()); 21. } What, inserted at line 12, is the appropriate way to handle a null value?() A、 assert value == null;B、 assert value !null, “value is null”;C、 if (value == null) { throw new AssertionException(”value is null”);D、 if (value == null) { throw new IllegalArgumentException(”value is null”);
考题
Which fragment is an example of inappropriate use of assertions? ()A、 assert (!(map.contains(x))); map.add(x);B、 if (x 0){}else { assert (x==0); }C、 public void aMethod(int x) { assert (x 0); }D、 assert (invariantCondition()); return retval;E、 switch (x) { case 1: break; case 2: creak; default: assert (x == 0);
考题
Given a method that must ensure that its parameter is not null: 11. public void someMethod(Object value) { 12. // check for null value ... 20. System.out.println(value.getClass()); 21. } What inserted at line 12, is the appropriate way to handle a null value?()A、assert value == null;B、assert value != null, "value is null";C、if (value == null) { throw new AssertionException("value is null"); }D、if (value == null) { throw new IllegalArgumentException("value is null"); }
考题
多选题Given: 11. // insert code here 12. private N min, max; 13. public N getMin() { return min; } 14. public N getMax() { return max; } 15. public void add(N added) { 16. if (min == null || added.doubleValue() max.doubleValue()) 19. max = added; 20. } 21. } Which two, inserted at line 11, will allow the code to compile?()AABBCCDDEEFF
考题
单选题interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?()A
public class Employee extends Info implements Data { public void load() { /*do something*/ } }B
public class Employee implements Info extends Data { public void load() { /*do something*/ } }C
public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }D
public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }E
public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }F
public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
考题
单选题11. public void someMethod(Object value) { 12. // check for null value .... 20. System.out.println(value.getClass()); 21. } What, inserted at line 12, is the appropriate way to handle a null value?()A
assert value == null;B
assert value !null, “value is null”;C
if (value == null) { throw new AssertionException(”value is null”);D
if (value == null) { throw new IllegalArgumentException(”value is null”);
考题
单选题下列选项中,能实现对父类的getSalary方法重写的是( )。
class Employee{
public double getSalary(){}
}A
class Manager extends Employee{
public int getSalary(double x){}
}B
class Manager extends Employee{
public double getSalary(int x,int y){}
}C
class Manager extends Employee{
public double getSalary(){}
}D
class Manager extends Employee{
public int getSalary(int x,int y){}
}
考题
单选题public class Test{ public static void main( String[] argv ){ // insert statement here } } Which statement, inserted at line 3, produces the following output?() Exception in thread “main” java.lang.AssertionError: true at Test.main(Test.java:3)A
assert true;B
assert false;C
assert false : true;D
assert false == true;E
assert false: false;
考题
单选题10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14. } And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine?()A
StackOverflowErrorB
NullPointerExceptionC
NumberFormatExceptionD
IllegalArgumentExceptionE
ExceptionlnlnitializerError
考题
单选题20. public float getSalary(Employee e) { 21. assert validEmployee(e); 22. float sal = lookupSalary(e); 23. assert (sal0); 24. return sal; 25. } 26. private int getAge(Employee e) { 27. assert validEmployee(e); 28. int age = lookupAge(e); 29. assert (age0); 30. return age; 31. } Which line is a violation of appropriate use of the assertion mechanism?()A
line 21B
line 23C
line 27D
line 29
考题
单选题Which fragment is an example of inappropriate use of assertions? ()A
assert (!(map.contains(x))); map.add(x);B
if (x 0){}else { assert (x==0); }C
public void aMethod(int x) { assert (x 0); }D
assert (invariantCondition()); return retval;E
switch (x) { case 1: break; case 2: creak; default: assert (x == 0);
考题
单选题11. public class Test { 12. public void foo() { 13. assert false; 14. assert false; 15. } 16. public void bar(){ 17. while(true){ 18. assert false; 19. } 20. assert false; 21. } 22. } What causes compilation to fail?()A
Line 13B
Line 14C
Line 18D
Line 20
热门标签
最新试卷