Exam 8: Objects and Classes

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

You have created a Motorcycle class which has a constructor with no parameters. Which of the following statements will construct an object of this class?

(Multiple Choice)
4.7/5
(40)

Insert the missing code in the following code fragment. This fragment is intended to initialize an instance variable. Public class Motor { Private int motorSpeed; ) . . Public Motor(int motorSpeed) { ________ } }

(Multiple Choice)
5.0/5
(36)

Consider the following code snippet: Public class Vehicle { Private String type; Private int numAxles; Public Vehicle(String vehicleType, int VehicleAxles) { . . . } Public Vehicle(String vehicleType) { . . . } } What is wrong with this code?

(Multiple Choice)
4.8/5
(40)

Consider the following class: Public class Auto { Private String make; Private String model; Private String year; Public Auto(String aMake, String aModel, String aYear) { Make = aMake; Model = aModel; Year = aYear; } Public String calcMileage(double milesDriven, double gasUsed) { Double milage = milesDriven/gasUsed; Return mileage.toString(); } } Which of the following code snippets will correctly create an object of type Auto and display its mileage?

(Multiple Choice)
4.7/5
(44)

Which choice indicates that a string variable refers to no string?

(Multiple Choice)
4.9/5
(40)

Which statement calls a constructor with no construction parameters?

(Multiple Choice)
4.9/5
(39)

Consider the following code snippet: Public class Transaction { Private int transactionCount; ) . . } Which of the following methods would correctly keep track of the total number of transactions?

(Multiple Choice)
4.8/5
(31)

Which of the following statements about class properties is correct?

(Multiple Choice)
4.8/5
(39)

If you do not provide a constructor in a class, which of the following is correct?

(Multiple Choice)
4.9/5
(31)

Which of the following statements about constructors is NOT correct?

(Multiple Choice)
4.9/5
(30)

Consider the following code snippet: Public class Course { Private int studentCount; ) . . } Which of the following methods would correctly keep track of the total number of enrollees in a course?

(Multiple Choice)
4.7/5
(34)

A method in a class that returns information about an object but does not change the object is called a/an ____ method.

(Multiple Choice)
4.8/5
(36)

Which of the following statements is true regarding classes?

(Multiple Choice)
4.9/5
(33)

Consider the following code snippet: Public class Employee { Private String empID; Private boolean hourly; Public Employee(String employeeID, boolean isHourly) { ) . . } } Which of the following statements can be used to create an object of type Employee?

(Multiple Choice)
4.9/5
(35)

Consider the following code snippet: Public class Vehicle { Private String type; Public String Vehicle(String type) { ) . . } } What is wrong with this code?

(Multiple Choice)
4.9/5
(38)

Which of the following statements about classes is correct?

(Multiple Choice)
4.8/5
(49)

When an object is created from a class, the object is called a/an ____ of the class.

(Multiple Choice)
4.8/5
(31)

You have created a Fruit class and a ShoppingCart class. Which of the following methods will correctly add a Fruit object to an array list named fruits in the ShoppingCart class?

(Multiple Choice)
4.8/5
(30)

Insert the missing code in the following code fragment. This fragment is intended to initialize an instance variable. Public class Vehicle { Int numAxles; Public Vehicle(int axles) { NumAxles = axles; } Public Vehicle() { _________; } } Which of the following lines of code will allow the second constructor to call the first constructor?

(Multiple Choice)
4.9/5
(44)

A constructor is invoked when ___ to create an object.

(Multiple Choice)
4.8/5
(36)
Showing 21 - 40 of 101
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)