1. An abstract class called Pet is defined below:  public abstract class Pet {  private String id; private String name;  private static int count = 0;  public Pet(String name)   {   count++;  id = "P" + count;  this.name = name;  }   public String toString()   {   return "ID: " + id + ", Name: " + name;  }  abstract public void sound(); }  The Cat class is a subclass of the Pet class. The class specifications are given below: • It has a private field named age to record the cat’s age. • The class constructor sets both name and age fields of the cat with the given parameter  values. The field age is set to 0 if the given value is negative.  • It provides an accessor method for the field age.  • It overwrites the toString method to return a string consisting of the cat’s ID, name and age. e.g. ID: P15, Name: Molly, Age: 4 • It prints out "Miaow" in a termina

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

1. An abstract class called Pet is defined below: 
public abstract class Pet

private String id;
private String name; 
private static int count = 0;
 public Pet(String name) 
 { 
 count++;
 id = "P" + count;
 this.name = name; 

 public String toString() 
 { 
 return "ID: " + id + ", Name: " + name; 

abstract public void sound();

The Cat class is a subclass of the Pet class. The class specifications are given below:
• It has a private field named age to record the cat’s age.
• The class constructor sets both name and age fields of the cat with the given parameter 
values. The field age is set to 0 if the given value is negative. 
• It provides an accessor method for the field age. 
• It overwrites the toString method to return a string consisting of the cat’s ID, name
and age. e.g.
ID: P15, Name: Molly, Age: 4
• It prints out "Miaow" in a terminal when the method sound is called. 
Define the Cat class in full. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY