1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
larisa [96]
3 years ago
8

Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of

type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field.
Computers and Technology
1 answer:
kozerog [31]3 years ago
6 0

Answer:

The program to this question can be given as:

Program:

class Horse   //define class Horse

{  

private String name;   //define variables.

private String color;  

private int birthYear;  

//define set method.

public void setName(String name)  

{  

this.name = name; //set value of name.

}

public void setColor(String color)  

{  

this.color = color; //set value of color.  

}  

public void setBirthYear(int birthYear)

{  

this.birthYear = birthYear;  //set value of birthYear

}  

//define get method.

public String getName()  

{  

return name;  //return name.

}  

public String getColor()

{  

return color;  //return color.

}  

public int getBirthYear()

{  

return birthYear;  //return birthYear.

}  

}

class RaceHorse extends Horse     //define class RaceHorse  

{

private String raceNum;            //define variable.

public void setRace(String raceNum)    //define set method.

{

 this.raceNum=raceNum;      //set value of raceNum.

}

public String getRace()

{

 return raceNum;   //return raceNum

}

}

public class Main      //define main class.

{

public static void main(String[] args) //define main method.

{

 Horse ob= new Horse();  //creating class objects.

 RaceHorse ob1 = new RaceHorse();

 ob.setName("XXX");       //calling function

 ob.setColor("BLACK");

 ob.setBirthYear(2008);

 ob1.setRace("Five hundred meter");

 //print return values.

       System.out.println("The name of the horse is " + ob.getName()+"." +"\n"+  

   "The horse's color is " + ob.getColor()+"."+"\n"+ "It was born in " + ob.getBirthYear() +  

   "."+"\n"+ ob.getName()+" has taken part in " + ob1.getRace() + " races.");

   

}

}

Output:

The name of the horse is XXX.

The horse's color is BLACK.

It was born in 2008.

XXX has taken part in Five hundred meter races.

Explanation:

In the above program firstly we declare the class that is Horse in this class we define a variable that name is already given in the question which are name, color, and birthYear. In these variables are name and color datatype is string and the birthYear datatype is an integer because it stores the number. Then we use the get and set function in the get function we return all variable value. and in the set function, we set the values of the variable by this keyword. Then we declare another class that is RaceHorse this class inherit Horse class. In the RaceHorse class, we define a variable that is raceNum that's data type is a string in this class we also used the get and set function. Then we declare the main class in the main class we define the main method in the main method we create the above class object and call the set and get function and print the values of the function.

You might be interested in
The file containing the definitions of the member functions of class DateType is called the ______ file.
Free_Kalibri [48]

Answer:

Implementation file

Explanation:

In popular object oriented programming languages like C/C++, The implementation file (source file) of a class is used to hold the code implementaion of the method(s) of the class, this is helpful for seperating interface and method implementation. When this seperation exists, header files will be used to declare all the methods and fields of the class.

In this way, the implementaion file will hold the actual source code of the methods that are declared in the header file and will have a line to include its associated header file. A major advantage of seperating code in this way is the enhancement of better code organization and code re-use

6 0
3 years ago
Wireless networks usually use ____ signals to send data.
barxatty [35]
<span>Wireless networks usually use radio (b) signals to send data. </span>
6 0
3 years ago
Read 2 more answers
3. Which swim_backwards method is called when sammy.swim_backwards() is executed? Why?
Georgia [21]
Classes called child classes or subclasses inherit methods and variables
4 0
2 years ago
For safety, the lights on your vehicle must be in good working condition. Which statement about
bija089 [108]
I think the answer is a but I am not for sure
7 0
3 years ago
Read 2 more answers
Which of the following kinds of computing refers to an environment of servers that house and provide access to resources users a
AveGali [126]

Answer:

Cloud is the correct answer for the above question.

Explanation:

Missing Information:

    The option is missing in the question and the question suggests to choice. The option can be liberated, cloud, disperse, digital for this question in which cloud is the correct answer.

Detailed Explanation:

  • The cloud is used to store a large amount of data or information for varies users and anyone can store or modify or delete the information from anywhere.
  • This service takes money from the user and gives service to modify, edit or add the data from anywhere using the internet. When a user wants to take the service of the cloud then he needs to contact the cloud service provider, then pays money to them and then he can enjoy the service.
  • The above question wants to ask about the term which is a vast environment of databases that provide access to the users to store and mane the data and that is the cloud which is the correct answer for the above question.
7 0
3 years ago
Other questions:
  • to prevent long page load time for pages containing images. It is best to use a compress file formatlike jpeg as well as appropr
    6·2 answers
  • What block cipher mode of operation involves each ciphertext block being fed back into the encryption process to encrypt the nex
    12·1 answer
  • Productivity can best be described as:
    5·2 answers
  • What part of the boot-up process initializes hardware and finds an operating system to load?
    14·1 answer
  • Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessar
    6·1 answer
  • ____ is a utility that can verify that TCP/IP is installed, bound to the NIC, configured correctly, and communicating with the n
    11·1 answer
  • A cybersecurity analyst is currently investigating a server outage. The analyst has discovered the following value was entered f
    9·1 answer
  • Select the correct answer.
    10·2 answers
  • 2.8 Code Practice: Question 2
    11·1 answer
  • Which software application offers a variety of templates for creating reports, flyers, and newsletters that you can access withi
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!