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 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; };
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...
To make class DressShirt inherit the functionality of both Clothing and Shirt (from previous question), the...
To make class DressShirt inherit the functionality of both Clothing and Shirt (from previous question), the class header would be: Group of answer choices public class DressShirt inherits Shirt, Clothing public class DressShirt inherits Shirt public class DressShirt extends Shirt public class DressShirt extends Shirt, Clothing If Shirt inherits Clothing, then Shirt has direct access to the ______ members of Clothing Group of answer choices public and protected public private protected private and protected Shirt inherits Clothing. What is the...
1. A constructor is a special Class member method. It is automatically called when an object...
1. A constructor is a special Class member method. It is automatically called when an object of the class is created. It can also be called more than once after the object is created. 2. In Java, the new operator is used to create an instance/object of a class in the heap. 3. A reference variable is a memory location contains an address of an object stored in the stack. 4. Encapsulation and abstraction are both the pillars of Object-Oriented...
How is coupling of transcription and translation possible in bacteria? Select all that apply. Select all...
How is coupling of transcription and translation possible in bacteria? Select all that apply. Select all that apply. as soon as an mRNA is transcribed, ribosomal subunits have physical access to it there are membranes separating the chromosome from ribosomes bacterial transcripts do not contain introns the primary transcript without the complete open reading frame bacterial ribosomes cannot translate the mRNA without pre-mRNA splicing
class DoubleLinkedList { public: //Implement ALL following methods. //Constructor. DoubleLinkedList(); //Copy constructor. DoubleLinkedList(const DoubleLinkedList & rhs);...
class DoubleLinkedList { public: //Implement ALL following methods. //Constructor. DoubleLinkedList(); //Copy constructor. DoubleLinkedList(const DoubleLinkedList & rhs); //Destructor. Clear all nodes. ~DoubleLinkedList(); // Insert function. Returns true if item is inserted, // false if the item it a duplicate value bool insert(int x); // Removes the first occurrence of x from the list, // If x is not found, the list remains unchanged. void remove(int x); //Assignment operator. const DoubleLinkedList& operator=(const DoubleLinkedList & rhs); private: struct node{ int data; node* next;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT