Question 1: Which of the following is true? Select all that apply. e. Constructo
ID: 3881786 • Letter: Q
Question
Question 1:
Which of the following is true? Select all that apply.
e. Constructors are used to initialize instance variables.
Question 2:
Write a class header for a class that would represent a car.
-----------------------------------------------------
In the next few questions, write a complete class called Book (described below).
A book is described by a title, author, ISBN code (see below), and publication year.
ISBN code is a unique 13-digit code assigned to all books. Codes might contain dashes. For example, the code for our textbook is 978-0133807806.
Question 3:
Write the class header and the instance data variables for the Book class.
Question 4:
Write a constructor for the Book class. The constructor should initialize the instance data variables using parameters.
Question 5:
Write accessor and mutator (getter and setter) methods. Include validity checking where appropriate.
Question 6:
Write a toString method to return a nicely formatted, multi-line description of the book.
Question 7:
Write code that would go inside of a main method.
The code should create three book objects and invoke at least two methods on each object. Also include a statement to print a text representation of one of the books to the console.
a. Constructors can invoke other methods in the class.Explanation / Answer
Answer)
Question 1:
Which of the following is true? Select all that apply.
a. Constructors can invoke other methods in the class. - True. A constructor can be used to invoke other methods in the class in Java.
b. A class can only have one constructor. - False. A class can have a default constructor and also parametrized constructors.
c. Constructors always have the same name as the class. - True. Constructors are named same as the class name so that the compiler knows before hand which method to call when an object is created.
d. The compiler always creates a default constructor (a constructor with no arguments) for a class. - True. The compiler creates a default constructor even if you do not explicitly define one.
e. Constructors are used to initialize instance variables. - True. Constructors in Java are used to initialize instance variables. It is the ideal point to initialize instance variables.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.