Fall- Quiz #2: Object-Oriented Programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

which of the following correctly explains the code snippet below?
public void doBlah(int a) {…}

a. the method takes in no parameters and returns an integer
b. the method takes in no parameters and returns nothing
c. the method takes in an integer parameter and returns nothing
d. the method header shown is not valid java code

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

class Aircraft is to have child classes Helicopter, Jet, and PropellerPlane. Which of the following is a correct class definition?

a. public class PropellerPlane extends Plan {…}
b. public class Aircraft extends Jet {…}
c. public class Helicopter extends Aircraft {…}
d. public class Jet {…}

A

c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

which are true?

  1. mutator methods allow clients outside of a class read data contained within an instance of a class
  2. accessor methods allow clients of a class read data contained within an instance of a class
  3. constructors allow for the creation of instances of a class
A

2 and 3 only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is the constructor of the class x

a. any statement in the program that creates an object of x
b. a special procedure in x’s definition that describes how objects of x can be created
c. any object in the program that creates an object of x
d. the new operator

A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

which of the following indicates that a method does not take any parameters?

a. empty parenthesis in the method’s header
b. no parenthesis in the method’s header
c. the keyword void in the method’s header inside parenthesis
d. the keyword void in the method’s header preceding the method’s name

A

a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

which of the following is not considered a programming best practice

a. data hiding/encapsulation
b. including a no-args constructor, even when java will automatically provide one
c. writing comments to enhance other’s ability to understand code
d. being careful not to feed gremlins

A

d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

write code that instantiates a class Planet into an object called planet1

A

Planet planet1= new Planet();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

write a mutator method, setPopulation(), that sets the value of population

A

public void setPopulation(int p) {
population=p;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly