4. Consider the following classes: public class Animal { public Animal(String itsName) { name public void setName (String itsName) { name public String getNane() { return name; } } } private String name; } public class Dog extends Animal public Dog(String itsName) { super(itsNane + "Dog"); sound = "Bark!"; { } public void şsetsaund(String itesound) { sound = public String getSound (0 { return (getName (0) + sound); public String getName (int choice) { if(choice > 0) return sypergetlans (); else return "AnxDea"; } public String getNane() { return surSKgetNans () + "OK"; } private String sound; } In addition, the following lines of code has been placed in a main class public static void main (String[] args) Animal al = new Animal("Tweety"); Animal a2 = new Dog ("Rover"); Dog d1 = new Dog("Spot"); } { Give the values of the following expressions. If an expression is erroneous, state why. a) al.getName() e) dl.getName() f) dl.getName(1) g) ((Animal) d1).getNane() h) ((Dog)al).getNane() i) d1 instanceef Animal j) al instanEsef Dog k) al.getSound () 1) a2.getSound () m) dl.getSound () n) ((Dog)a2).getseund () ( (Animal) dl).getsewnd() b) a2.getName() c) a2.getName (0) invalid because the function has no parameter but the parameter 0 is provided here. So this is invalid. d) (new Animal ()).getNane () o) 5. Which of the following best illustrates the concept of polymorphism? Why? i) That a) and b) have different answers. ii) That e) and f) have different answers. iii) That k) and 1) have different answers.
4. Consider the following classes: public class Animal { public Animal(String itsName) { name public void setName (String itsName) { name public String getNane() { return name; } } } private String name; } public class Dog extends Animal public Dog(String itsName) { super(itsNane + "Dog"); sound = "Bark!"; { } public void şsetsaund(String itesound) { sound = public String getSound (0 { return (getName (0) + sound); public String getName (int choice) { if(choice > 0) return sypergetlans (); else return "AnxDea"; } public String getNane() { return surSKgetNans () + "OK"; } private String sound; } In addition, the following lines of code has been placed in a main class public static void main (String[] args) Animal al = new Animal("Tweety"); Animal a2 = new Dog ("Rover"); Dog d1 = new Dog("Spot"); } { Give the values of the following expressions. If an expression is erroneous, state why. a) al.getName() e) dl.getName() f) dl.getName(1) g) ((Animal) d1).getNane() h) ((Dog)al).getNane() i) d1 instanceef Animal j) al instanEsef Dog k) al.getSound () 1) a2.getSound () m) dl.getSound () n) ((Dog)a2).getseund () ( (Animal) dl).getsewnd() b) a2.getName() c) a2.getName (0) invalid because the function has no parameter but the parameter 0 is provided here. So this is invalid. d) (new Animal ()).getNane () o) 5. Which of the following best illustrates the concept of polymorphism? Why? i) That a) and b) have different answers. ii) That e) and f) have different answers. iii) That k) and 1) have different answers.
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...
Related questions
Question
JAVA
I need help on question 5, Please and thank you so much!
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Recommended textbooks for you
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY