Answered step by step
Verified Expert Solution
Question
1 Approved Answer
a) If a Pet object were created as follows: Pet pet1- new Pet() What will be values of instance variables legs, eat, fleas and bas@wner
a) If a Pet object were created as follows: Pet pet1- new Pet() What will be values of instance variables legs, eat, fleas and bas@wner for pet1? Answer: b) Write a full-arg constructor for Pet class. Answer: c Write a 2-arg constructor for Pet class using parameters for values of fleas and baswner. Answer d) Write/modify the printPetlnstVar) method of the Pet class, if the instance variables of the super and sub classes were all declared private Answer: e) Create two Pet objects pet1 and pet2 using default and full-augconstructors, respectively Answer f) Create two Animal objects, animal1 and animal2, using default and full-arg constructor, respectively. Answer g) Call all the setters for animal1 object [created in step f).Use any appropriate values to set the instance variables. Answer h) Call all the setters for Answer instance variables both native and inherited) of petl object ( created in step e) .Use any appropriate values to set the instance variables. i) Assume there is another instance variable in Pet class called petTyee of String type. Write a method setPetteethat will set the value of eetI using the following logic. If the value of legs is 0, Retwe is "Snake-If the value of legs is 2, legged"; else"insect" RetwR: "monkey ; if the value of Retwes s 4, ReDRe, four Answer j) Call ettee method described in the problem above, for pet1 object. Answer Suppose the Pet class has another sub class called Cat. Assume this class has a private Boolean instance variable called likesToScratch. Override the printPetlnstVa) method by printing out only the value of likesTgScratch and basQwner k) Answer: I) Suppose the Pet class has another sub class called Cat. Assume this class has a Boolean instance variable called likesToScratch, Override the printPetlnstVar) method by printing out the values of all instance variables including those of the Pet class and those of the Cat class. Answer m) Suppose the Pet class has another sub class called Cat. Override the getFleas method by doubling the value returned by the super class's getFleas method
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started