Answer:
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.
}
}
Step-by-step 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.