Fall- Quiz #2: Object-Oriented Programming Flashcards
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
c
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 {…}
c
which are true?
- mutator methods allow clients outside of a class read data contained within an instance of a class
- accessor methods allow clients of a class read data contained within an instance of a class
- constructors allow for the creation of instances of a class
2 and 3 only
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
b
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
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
d
write code that instantiates a class Planet into an object called planet1
Planet planet1= new Planet();
write a mutator method, setPopulation(), that sets the value of population
public void setPopulation(int p) {
population=p;
}