Question

Assume a class, OOFClass, defines a constructor with no arguments. You are editing OOFClass, and you...

Assume a class, OOFClass, defines a constructor with no arguments. You are editing OOFClass, and you want to create a new constructor that reuses the existing constructor to do some of the work. How would you call that constructor?

Select one:

a. super(), called anywhere in the old constructor

b. this(), called anywhere in the old constructor

c. super(), called as the first command in the new constructor

d. super(), called as the first command in the old constructor

e. this(), called anywhere in the new constructor

f. this(), called as the first command in the old constructor

g. super(), called anywhere in the new constructor

h. this(), called as the first command in the new constructor

Homework Answers

Answer #1

Answer is:

h. this(), called as the first command in the new constructor.

This is clearly infered from the following example code in java:-

class OOF
{
// default constructor 1
OOF()
{
System.out.println("default constructor");
}
// parameterized constructor 1 (new constructor)
OOF(int x)
{
// invokes default constructor
this();
System.out.println(x);
}
public static void main(String args[])
{
// invokes parameterized constructor 2
new OOF(100);
}
}

And hence it prints output as:-

default constructor

100

Note:-

  1. The this() should always be the first line of the constructor.
  2. There should be at-least be one constructor without the this() because if all constructors have this() then there is no end for the programs and runs into infinite loop.
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a sub class's constructor? Select one: a. It must be the first statement in the constructor b. If you don't include it Java will c. If you don't include it you must have a 0 parameter constructor coded in the super class or no constructors coded at all in the super class d. The sub class constructor containing the super call and the called super...
TrackMinMax For this lab, you will create a generic version of the IntTrackMinMax class you wrote...
TrackMinMax For this lab, you will create a generic version of the IntTrackMinMax class you wrote in a previous lab, called TrackMinMax. The API is: Function Signature Description constructor TrackMinMax() constructor check void check(T i) compares i to the current minimum and maximum values and updates them accordingly getMin T getMin() returns the minimum value provided to check() so far getMax T getMax() returns the maximum value provided to check() so far toString String toString() returns the string "[min,max]" As...
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
Using Inheritance Consider the following (base) class. class Employee(object): def __init__(self, name, salary): self._name = name...
Using Inheritance Consider the following (base) class. class Employee(object): def __init__(self, name, salary): self._name = name self._salary = salary def my_name(self): return self._name def wage(self): return self._salary/26 # fortnight pay Define a new subclass of Employee called Worker. A worker has a manager, who is another employee; their manager is given as an argument to the constructor. You should define a method get_manager that returns the worker’s manager. boss = Employee('Mr. Burns', 1000000) worker = Worker('Waylon Smithers', 2500, boss) Define...
assume you are in main.cpp define a function that is NOT SCOPED to any class. It...
assume you are in main.cpp define a function that is NOT SCOPED to any class. It is NOT a member of the ListInterface nor LinkedList classes. Your function should accept two lists. You will remove all values from the first list that are present in the second list. Example: Lists before call:                                                          Lists after call: target: A, B, C, A, D, C, E, F, B, C, A                        target: A, A, D, E, F, A toRemove: C, B, Q,...
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h...
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h andRun.cpp to separate class header and implementation. In this program, we are going to create a small scale Telivision Management System. A) Create a class Episode with following variables: char* episode_name, char* episode_venue, char episode_date[22] and char episode_time[18]. Input format for episode_date: dd-mm-yyyy Input format for episode_time: hh:mm am/pm B) Implement default constructor and overloaded constructor. Print “Default Constructor Called” and “Overloaded Constructor Called”...
IntNode class I am providing the IntNode class you are required to use. Place this class...
IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is. struct IntNode { int data; IntNode *next;...
1. Write a function called compute_discount which takes a float as the cost and a Boolean...
1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass...
Compile and execute the application. You will discover that is has a bug in it -...
Compile and execute the application. You will discover that is has a bug in it - the filled checkbox has no effect - filled shapes are not drawn. Your first task is to debug the starter application so that it correctly draws filled shapes. The bug can be corrected with three characters at one location in the code. Java 2D introduces many new capabilities for creating unique and impressive graphics. We’ll add a small subset of these features to the...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT