Question

In: Computer Science

Shirt inherits clothing. In the Shirt constructor, how is the Clothing default constructor called? (Select all...

Shirt inherits clothing. In the Shirt constructor, how is the Clothing default constructor called? (Select all that apply)

Group of answer choices

super();

Clothing();

Clothing.Clothing()

Make no explicit call

Shirt inherits Clothing. In the Shirt constructor, how is a Clothing constructor with one int parameter called?

For the answer, assume that an int variable called "myInt" is in scope.

Group of answer choices

Clothing.Clothing(myInt);

Clothing(myInt);

super(myInt);

Make no explicit call

Shirt inherits Clothing. Both classes have their own version of the method fold(). Which fold() is executed in the following code?

Shirt myShirt = new Shirt();

myShirt.fold();

Group of answer choices

The Clothing version

The Shirt version

Both, Shirt and then Clothing

Both, Clothing and then Shirt

Solutions

Expert Solution

Question:
Shirt inherits clothing. In the Shirt constructor, how is the Clothing default constructor called? (Select all that apply)
Ans:
super();

  • Here the class shirt inherits Clothing. Whenever we need to invoke the Clothing default constructor
  • We need to use the super() keyword in order to call the clothing default constructor.

Question:
Shirt inherits Clothing. In the Shirt constructor, how is a Clothing constructor with one int parameter called?
For the answer, assume that an int variable called "myInt" is in scope.
Ans:
super(myInt);

  • As mentioned above if there is no parameter we can simply use super()
  • If it is having an int parameter for the function call then we need to use super(myInt)

Question:
Shirt inherits Clothing. Both classes have their own version of the method fold(). Which fold() is executed in the following code?
Shirt myShirt = new Shirt();
myShirt.fold();
Ans: The Clothing version

  • This is the case of overriding rule, As per the rule we need to call the child class first since because of the static nature,
  • It is not possible to override the method and will call the Superclass which is Clothing. It will invoke the Clothing version.

(Feel free to drop me a comment, If you need any help)


Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...


Related Solutions

Shirt inherits Clothing. Clothing has the fold()method, but Shirt does not. Which fold() is executed in...
Shirt inherits Clothing. Clothing has the fold()method, but Shirt does not. Which fold() is executed in the following code? Shirt myShirt = new Shirt(); myShirt.fold() Group of answer choices This results in a runtime error. The Shirt version This results in a compiler error. The Clothing version Shirt inherits Clothing. What would be the effect of the following code? Clothing myShirt = new Shirt(); Group of answer choices The code compiles and runs. A compiler error A runtime error Shirt...
Java- Write a class called Rectangle that inherits from Shape. Write a constructor that has length,...
Java- Write a class called Rectangle that inherits from Shape. Write a constructor that has length, width and colour as arguments. Define enough functions to make the class not abstract
(1) default constructor which initalizes all the coefficients to 0 (2) a constructor that takes three...
(1) default constructor which initalizes all the coefficients to 0 (2) a constructor that takes three parameters public QuadraticExpression(double a, double b, double c) (3) a toString() method that returns the expression as a string. (4) evaluate method that returns the value of the expression at x public double evaluate(double x) (5) set method of a, b, c public void setA(double newA) public void setB(double newB) public void setC(double newC) (6) public static QuadraticExpression scale( double r, QuadraticExpression q) returns...
What is a constructor ? What is a destructor? What is a default constructor? Is it...
What is a constructor ? What is a destructor? What is a default constructor? Is it possible to have more than one default constructor?
Define the exception class called TornadoException. The class should have two constructors including one default constructor....
Define the exception class called TornadoException. The class should have two constructors including one default constructor. If the exception is thrown with the default constructor, the method getMessage should return "Tornado: Take cover immediately!" The other constructor has a single parameter, m, of int type. If the exception is thrown with this constructor, the getMessage should return "Tornado: m miles away; and approaching!" Write a Java program to test the class TornadoException.
in c++ a Circle should be created with the default constructor, then its area, diameter, and...
in c++ a Circle should be created with the default constructor, then its area, diameter, and circumference printed to the screen for verification that it has the correct state and those respective methods work correctly. Then, output of the state should be repeated after calling each mutator to ensure that the object’s new state reflects the change Create a Circle class with the class implementation in a file named circle.cpp and the class declaration in a file named circle.h (or...
Define the following class: class XYPoint { public: // Contructors including copy and default constructor //...
Define the following class: class XYPoint { public: // Contructors including copy and default constructor // Destructors ? If none, explain why double getX(); double getY(); // Overload Compare operators <, >, ==, >=, <=, points are compare using their distance to the origin: i.e. SQR(X^2+Y^2) private: double x, y; };
public class GroceryCart { private static final int DEFAULT_CAPACITY = 10; /* * Default constructor with...
public class GroceryCart { private static final int DEFAULT_CAPACITY = 10; /* * Default constructor with zero arguments. This constructs a grocery * cart with a default capacity of ten items. */ public GroceryCart() { } /* * Alternate constructor which takes in a maxCapacity. This maxCapacity * determines how many items can fit inside of this groceryCart. */ public GroceryCart(int maxCapacity) { } /* * Adds an item to the grocery cart. Returns true if the item was added...
C++ existing code #include "ArrayBag.hpp" #include <iostream> /****************************************************** Public Methods *****************************************************/ /* Default Constructor */ template...
C++ existing code #include "ArrayBag.hpp" #include <iostream> /****************************************************** Public Methods *****************************************************/ /* Default Constructor */ template <typename ItemType> ArrayBag<ItemType>::ArrayBag() : item_count_(0) { // initializer list } // end default constructor template <typename ItemType> int ArrayBag<ItemType>::getCurrentSize() const { return item_count_; } template <typename ItemType> bool ArrayBag<ItemType>::isEmpty() const { return item_count_ == 0; } template <typename ItemType> bool ArrayBag<ItemType>::add(const ItemType &new_entry) {    bool has_room_to_add = (item_count_ < DEFAULT_CAPACITY); if (has_room_to_add) { items_[item_count_] = new_entry; item_count_++; } // end if return has_room_to_add;...
Hi all! Looking for good explanations as to how this problem is solved without the constructor....
Hi all! Looking for good explanations as to how this problem is solved without the constructor. 1. In this problem, we will write and use a static class (remember static classes do not operate on an object.) Your weight is actually the amount of gravitational attraction exerted on you by the Earth. Since the Moon’s gravity is only one-sixth of the Earth’s gravity, on the Moon you would weigh only one-sixth of the Earth’s gravity. Write an application that inputs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT