I need this in Java please: Lab11B: Understanding the constructor. Remember that the constructor is just a...

90.2K

Verified Solution

Question

Programming

I need this in Java please:

Lab11B: Understanding the constructor. Remember that theconstructor is just a special method (with no return type) that hasthe same name as the class name. Its job is to initialize all ofthe attributes. You can actually have more than one constructor, solong as the parameters are different. Create a class called Turtlethat has two attributes: 1) speed and 2) color. Then, create aconstructor that has no parameters, setting the default speed to 0and the color to “green”; this is called a default constructor.Next, create a second constructor that takes in two parameters. Thesecond constructor should assign those parameters to theattributes. Then, in main, create two Turtle objects. For the firstTurtle object, call the first constructor. For the second Turtleobject, call the second constructor (passing it a speed of 5 and acolor of “purple”). Using the dot ‘.’ Operator, print out the firstturtle’s speed and the second turtle’s color. This is a test to seeif you can design constructors inside your class and initializeattributes.

Answer & Explanation Solved by verified expert
3.7 Ratings (429 Votes)
I have uploaded the Images of the code Typed code and Output ofthe Code I have provided explanation using comments read them forbetter understandingImages of the CodeNote If the below code is missing indentation please refercode ImagesTyped Code A class    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students