CS 2420 Midterm 1 UPDATED ACTUAL and Correct Answers
Question: What prints?
double d = 3.14;
int i = (int)d;
System.out.println("d is " + d + " and i is " + i);
Answer:
d is 3.14 and i is 3
Question: What prints
boolean b = true;
if(10 > 100 && b)
System.out.print("1");
else
System.out.print("2");
if(10 > 100 || b)
System.out.println("3");
Answer:
23
Question: What prints
Point p1 = null;
if(true)
p1 = new Point();
p1.x = 3;
p1.y = -5;
Point p2 = p1;
p2.x = 10;
System.out.println("p1.x is " + p1.x + " and p2.x is " + p2.x);
Answer:
p1.x is 10 and p2.x is 10
Question: What is the testing technique in which the smallest testable parts of an application are
individually and independently tested for correctness called?
Answer:
unit
testing
, Question: All methods that are members of an interface are abstract
Answer:
true
Question: All members of an interface (methods and data) are public
Answer:
true
Question: A class that implements an interface must not perform any method overloading
Answer:
false
Question: All methods that are members of an interface must have a return type of
void
Answer:
false
Question: All abstract classes are interfaces
Answer:
false
Question: class Person { public String getAddress() ... }
class Employee extends Person { public double getSalary() ... }
class Student extends Person { public String toString() ... }
class GradStudent extends Student { public boolean equals(Object other) ... }
Employee e = new Employee();
Student s = new GradStudent();
Person p = e;
Object o = s;
Answer:
Question: What is true of the method call p.getSalary()?
Answer:
Question: What is true of the method call s.toString()?
Answer:
Question: What prints?
double d = 3.14;
int i = (int)d;
System.out.println("d is " + d + " and i is " + i);
Answer:
d is 3.14 and i is 3
Question: What prints
boolean b = true;
if(10 > 100 && b)
System.out.print("1");
else
System.out.print("2");
if(10 > 100 || b)
System.out.println("3");
Answer:
23
Question: What prints
Point p1 = null;
if(true)
p1 = new Point();
p1.x = 3;
p1.y = -5;
Point p2 = p1;
p2.x = 10;
System.out.println("p1.x is " + p1.x + " and p2.x is " + p2.x);
Answer:
p1.x is 10 and p2.x is 10
Question: What is the testing technique in which the smallest testable parts of an application are
individually and independently tested for correctness called?
Answer:
unit
testing
, Question: All methods that are members of an interface are abstract
Answer:
true
Question: All members of an interface (methods and data) are public
Answer:
true
Question: A class that implements an interface must not perform any method overloading
Answer:
false
Question: All methods that are members of an interface must have a return type of
void
Answer:
false
Question: All abstract classes are interfaces
Answer:
false
Question: class Person { public String getAddress() ... }
class Employee extends Person { public double getSalary() ... }
class Student extends Person { public String toString() ... }
class GradStudent extends Student { public boolean equals(Object other) ... }
Employee e = new Employee();
Student s = new GradStudent();
Person p = e;
Object o = s;
Answer:
Question: What is true of the method call p.getSalary()?
Answer:
Question: What is true of the method call s.toString()?
Answer: