Ask Question

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. 16 March, 13:20
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers