Question

In: Computer Science

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 inherits Clothing. What would be the effect of the following code?

Shirt myShirt = new Clothing();

Group of answer choices

A runtime error

The code compiles and runs.

A compiler error

Solutions

Expert Solution

Answers:

Question 1: The Clothing version

-> As the Shirt inherits Clothing so the object of the Shirt class can call the method of Clothing.

Program:

class Clothing
{
void fold()
{
System.out.println("Clothing class Method!!");
}
}
class Shirt extends Clothing
{
}

class Test
{
public static void main(String args[])
{
Shirt myShirt=new Shirt();
myShirt.fold();
}
}

Output:

Question 2: The code compiles and runs.

Program:

class Clothing
{
void fold()
{
System.out.println("Clothing class Method!!");
}
}
class Shirt extends Clothing
{
}

class Test
{
public static void main(String args[])
{
Clothing myShirt=new Shirt();
myShirt.fold();
}
}

Output:

Question 3: A compile error

-> Compile error: incompatible types: Clothing cannot be converted to Shirt.

Program:

class Clothing
{
void fold()
{
System.out.println("Clothing class Method!!");
}
}
class Shirt extends Clothing
{
}

class Test
{
public static void main(String args[])
{
Shirt myShirt = new Clothing();
myShirt.fold();
}
}

Output:


Related Solutions

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...
Take a piece of paper and fold it in half. Unfold it and there is one fold, which I'll signify with a "v". If you fold the paper twice
Use C#  RECURSION - PAPERFOLDS Concept Summary: 1. Recursion For this assignment1 you will design a recursive method and the main program that calls the recursive method. Description Take a piece of paper and fold it in half. Unfold it and there is one fold, which I'll signify with a "v". If you fold the paper twice (always keeping the folds in the same direction and the creases parallel), it will have three folds when you unfold it, and they...
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...
Sophia inherits inherited money from her grandparents. She inherits $100,000 from her grandparents, today. She has...
Sophia inherits inherited money from her grandparents. She inherits $100,000 from her grandparents, today. She has exactly 20 years to retire and she decided to put the entire amount into 20 years, 4% annual interest annuity. A) Assume that she did not deposit any additional amount into this account, compute your account balance by the time she retires. Please compute the problem using a scientific calculator (not a financial one) using the appropriate formulas and show your calculations step by...
Which method(s) of energy transfer does not require matter? Which method(s) of energy transfer does require...
Which method(s) of energy transfer does not require matter? Which method(s) of energy transfer does require matter? Give an example of each
A lecture hall at NC State has 215 seats with fold-down writing pedestals, 25 of which...
A lecture hall at NC State has 215 seats with fold-down writing pedestals, 25 of which are designed for left-handers. An Intro. to Economics class with 215 students meets in this lecture hall. Assume that 13% of the general population is left-handed. Question 1. What is the probability that at least one right-handed student in this class is forced to use a seat designed for a left-hander? (Use 4 decimal places.) Question 2. What is the probability that at least...
Warrier Gear manufactures clothing. A flannel shirt requires the following: Standard Direct Materials 2 square yards...
Warrier Gear manufactures clothing. A flannel shirt requires the following: Standard Direct Materials 2 square yards at $15 per yard Standard Manufacturing Labor 1.5 hours at $25 per hour During the third quarter, the company made 1,500 shirts and used 3,200 square yards of fabric costing $44,800. Direct labor totaled 2,100 hours for $56,700. Required: (A) Compute the direct materials price and efficiency variances for the quarter. (B) Compute the direct manufacturing labor price and efficiency variances for the quarter....
Warrier Gear manufactures clothing. A flannel shirt requires the following: Standard Direct Materials 2 square yards...
Warrier Gear manufactures clothing. A flannel shirt requires the following: Standard Direct Materials 2 square yards at $15 per yard Standard Manufacturing Labor 1.5 hours at $25 per hour During the third quarter, the company made 1,500 shirts and used 3,200 square yards of fabric costing $44,800. Direct labor totaled 2,100 hours for $56,700. Required: (A) Compute the direct manufacturing labor price and efficiency variances for the quarter. Show all computations. (B) Describe 2 possible reasons for each of the...
Warrier Gear manufactures clothing. A flannel shirt requires the following: Standard Direct Materials 2 square yards...
Warrier Gear manufactures clothing. A flannel shirt requires the following: Standard Direct Materials 2 square yards at $15 per yard Standard Manufacturing Labor 1.5 hours at $25 per hour During the third quarter, the company made 1,500 shirts and used 3,200 square yards of fabric costing $44,800. Direct labor totaled 2,100 hours for $56,700. Required: (A) Compute the direct materials price and efficiency variances for the quarter. Show all computations. (B) Compute the direct manufacturing labor price and efficiency variances...
1. Under which condition a firm can recognize its sales? Select one: a. Seller has executed...
1. Under which condition a firm can recognize its sales? Select one: a. Seller has executed substantially all the requirements of the agreement b. The risk of the product has passes c. Revenue must be earned by transferring the risk and fulfilling the agreement, and Revenue must be realized or realizable d. Received cash or cash equivalent 2. When the firm received a notice from a customer that he is not able to make the payment, the firm decides to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT