Ask Question
27 January, 17:40

Create a segment of code that initializes a public class Fish. Let the class contain a String typeOfFish, and an integer friendliness. Do not set values to these variables yet. These are instance variables and will be set inside the class constructors.

+3
Answers (1)
  1. 27 January, 18:10
    0
    The code to the given question as follows:

    Code:

    public class Fish / /defining class

    {

    private String typeOfFish; / /defining variable

    private int friendliness; / /defining variable

    Fish (String typeOfFish, int friendliness) / /parameterized constructor.

    {

    super (); / /calling

    this. typeOfFish = typeOfFish; / /holds value in variable.

    this. friendliness = friendliness; / /holds value in variable.

    }

    }

    Explanation:

    In the above code, a class "Fish" is defined that contains two private variables that are "typeOfFish and friendliness" in which typeOfFish is a string type variable and friendliness is an integer type variable. In this class, a parameterized constructor is defined, which includes these variables as a parameter and inside this constructor, the super keyword and this keyword is used. Super keyword and this keyword both is a reference variable, but the super keyword is used to call the above class or parents class object and this keyword is used as a reference to holding the current object.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Create a segment of code that initializes a public class Fish. Let the class contain a String typeOfFish, and an integer friendliness. Do ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers