Ask Question
26 October, 10:26

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.

+4
Answers (1)
  1. 26 October, 11:27
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers