Question

Create a public constructor (a method with the same name as the class) inside the class...

Create a public constructor (a method with the same name as the class) inside the class Fish. This constructor should take in no arguments. Inside the constructor, set typeOfFish to “Unknown” and friendliness to 3, which we are assuming is the generic friendliness of fish.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

\color{red}\underline{Constructor:}

public Fish() {
    typeOfFish = "Unknown";
    friendliness = 3;
}

\color{red}below\;is\;complete\;fish\;class\;with\;constructor

public class Fish {

    private String typeOfFish;
    private int friendliness;

    public Fish() {
        typeOfFish = "Unknown";
        friendliness = 3;
    }
}
Add a comment
Know the answer?
Add Answer to:
Create a public constructor (a method with the same name as the class) inside the class...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 10. Inside the class Student, we see the following code for the constructor: public Student(String name)...

    10. Inside the class Student, we see the following code for the constructor: public Student(String name) { name = name } Unfortunately, Java gives us an error when we compile this code. Rewrite this constructor in the best way to correct the problem?

  • Implement the following class in Java. Class name: Cakes Constructor Summary: public Leaderboard() - Create a...

    Implement the following class in Java. Class name: Cakes Constructor Summary: public Leaderboard() - Create a leaderboard with no entries, and current number of cakes eaten to 0. Methods: public List getContestants() - Return a list of all the contestant scores in the format (Name:Score). Return an empty list if no entries inside list. Please provide a test to show your implementation works, thank you.

  • Course Class Create a class called Course. It will not have a main method; it is...

    Course Class Create a class called Course. It will not have a main method; it is a business class. Put in your documentation comments at the top. Be sure to include your name. Course must have the following instance variables named as shown in the table: Variable name Description crn A unique number given each semester to a section (stands for Course Registration Number) subject A 4-letter abbreviation for the course (e.g., ITEC, PHED, CHEM) number A 4-digit number associated...

  • Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...

    Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...

  • Create a Python class called Rectangle. The constructor for this class should take two numeric arguments,...

    Create a Python class called Rectangle. The constructor for this class should take two numeric arguments, width and height. Add a method isEqual that determines if one rectangle is equal to another. Python Please!

  • Create a LIFO class with following methods in java - public LifoList() The default constructor for...

    Create a LIFO class with following methods in java - public LifoList() The default constructor for LifoList class which will initialize your class variables maxSize to 0 and the int array to null. public LifoList(int maxSize) The constructor for LifoList class which takes the int input maxSize to initialize the size of the array. You should NOT reinitialize the array elsewhere. For example, creating an object as new LifoList(5) should create a LifoList whose maximum size is 5. If the...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

  • Create a class called planet with private members name, percent02, temp. Create a constructor prototype and...

    Create a class called planet with private members name, percent02, temp. Create a constructor prototype and implementation. In the main, create 2 objects of class planet, one with arguments and the other without. Create a function to change name, percent02 and temp after the object has been created and a function that displays the current values of the members. Implement the operations specified above in the main of your program. This is all in C++, please help.

  • Homework assignment need help 3. Create the constructor, area and toString method for the following class...

    Homework assignment need help 3. Create the constructor, area and toString method for the following class (2 point) public class. Square private double a; Ll...area of square is a*a In the test class replace commented lines with your code. public class. Test Square public static void main (String[] args) // Create an instance of Square I. Print the area using area method // Print the instance using toString method

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT