Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 19.8, Problem 19.8.3CP
Explanation of Solution
“No”, the user cannot create an instance using “new E()” for generic-type parameter “E”.
Explanation:
- The reason is, the in...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Java:
Code a generic class called Location that describes a point in the xy plane. The Location class requires instances variables to represent the x and y coordinates, a parameterized constructor, one method to change both coordinates of the point (both x and y), getX and getY methods and a toString. These are the only methods in this class. The class uses a generic type so that any numeric value can be used for the coordinates (2 integers, 2 floats, 2 doubles, etc) or 2 Strings (for example three and ten).
Write a code segment in main( ) to thoroughly test the class Location. Your code segment should create two locations, one represented by a pair of real numbers and one represented by a pair of Strings.
Explore the role of generics in conjunction with the Comparable interface. How do generics enhance type safety when sorting collections of objects?
Discuss what is meant by a generic class
Chapter 19 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 19.2 - Are there any compile errors in (a) and (b)?Ch. 19.2 - Prob. 19.2.2CPCh. 19.2 - Prob. 19.2.3CPCh. 19.3 - Prob. 19.3.1CPCh. 19.3 - Prob. 19.3.2CPCh. 19.3 - Prob. 19.3.3CPCh. 19.3 - Prob. 19.3.4CPCh. 19.4 - Prob. 19.4.1CPCh. 19.4 - Prob. 19.4.2CPCh. 19.5 - Prob. 19.5.1CP
Ch. 19.5 - Prob. 19.5.2CPCh. 19.6 - What is a raw type? Why is a raw type unsafe? Why...Ch. 19.6 - Prob. 19.6.2CPCh. 19.7 - Prob. 19.7.1CPCh. 19.7 - Prob. 19.7.2CPCh. 19.7 - Prob. 19.7.3CPCh. 19.7 - Prob. 19.7.4CPCh. 19.8 - Prob. 19.8.1CPCh. 19.8 - Prob. 19.8.2CPCh. 19.8 - Prob. 19.8.3CPCh. 19.8 - Prob. 19.8.4CPCh. 19.8 - Prob. 19.8.5CPCh. 19.9 - Prob. 19.9.1CPCh. 19.9 - How are the add, multiple, and zero methods...Ch. 19.9 - How are the add, multiple, and zero methods...Ch. 19.9 - What would be wrong if the printResult method is...Ch. 19 - (Revising Listing 19.1) Revise the GenericStack...Ch. 19 - Prob. 19.2PECh. 19 - (Distinct elements in ArrayList) Write the...Ch. 19 - Prob. 19.4PECh. 19 - (Maximum element in an array) Implement the...Ch. 19 - (Maximum element in a two-dimensional array) Write...Ch. 19 - Prob. 19.7PECh. 19 - (Shuffle ArrayList) Write the following method...Ch. 19 - (Sort ArrayList) Write the following method that...Ch. 19 - (Largest element in an ArrayList) Write the...Ch. 19 - Prob. 19.11PE
Knowledge Booster
Similar questions
- If you have a generic class : public class Search<A, B> how can you find all the occurences of B in the searcharrow_forwardWhat does the following code block define? class Gen { T ob; } A. Generics class decleration B. Decleration of variable C. a simple class decleration D. Both a & barrow_forwardIn JAVA please Write a generic AddressBook<E extends Person> class that manages a collection ofPerson objects. The AddressBook class is a generic class limited to person objects. Forexample, once you instantiate an AdressBook of Student objects, you cannot add anyother type of person objects into that instance of address book.The AddressBook should have methods to add, delete, or search for a Person objects inthe address book.• The add method should add a person object to the address book. Make sure thatthe add method does not add duplicate person objects to the address book.• The delete method should remove the specified person object from the addressbook.• The search method that searches the address book for a specified person andreturns the list of persons matching the specified criteria. The search can be doneeither by first name, last name, or person id.Write an AddressBookTester class to test your class.arrow_forward
- Write Java code to create a generic class that stores two generic objects. Create an instance of this same generic class and store three objects of the String class in it.arrow_forwardWrite a generic class with a type parameter T, which declares a T[] and provides: a. A constructor that initializes T[). b. A method that calculates the average of T[] and then returns it. c. A method that displays the average of T[] on screen. Tis a Number class or a subclass of Number class. Write a GenericTest class that tests your generic class with Integer and Double arrays. You can choose the values of the arrays for testing your generic classarrow_forwardGive an example of a program that uses the nongeneric version of a class from the Java Collection Framework and the equivalent program that uses the generic version. How do the two implementations differ? Why is having the syntax of generics better?arrow_forward
- Create a SameItem Interface: The SameItem interface will be a generic interface.SameItem will have a single method: isSameAs(T) that returns a booleanarrow_forwardjava Declare a generic interface called Pair that takes two type parameters K and V. This interface has two methods getKey that returns a value of type K, and getValue that returns a value of type V. Write a class OrderedPair implementing the Pair interface. The class has two instance variables which are key (of type K) and value (of type V). Define the constructor of the class OrderedPair that initializes the instance variables. In a class named Util, define a generic method, compare, which compares two Pair objects. Based on equals method inherited from the Object class, returns true if the keys and values of the two pairs are equal. Test your compare method. Write and test a generic method countGreaterThan that receives an array from any type that implements the Comparable interface and a parameter e of the same type. The method counts and returns the array elements that are greater than e.arrow_forward1. Follow the class instruction and complete the Cat class. Create class Cat a. Add properties: i. What characteristics do they have? Name, age, color, type (domestic / feral), etc. (secure the data) ii. What color(s) might they have? White, cream, fawn, Cinnamon, Chocolate, Red, Lilac, Blue, Black, Lavender, etc. b. Add methods: eat()), play(), etc. c. Constructors? i. A class provides a special type of methods, known as constructors, which are invoked to construct objects from the class ii. Create 2 different constructor with different initialization parameters d. How to get the number of cats? Add a static variable and a static method to print out the number of cats. e. Test Cat class by creating 3 Cat instances: i. Each cat should have different properties. ii. Test all the methods. iii. Print out the number of cats. 2. Define a BankAccount class that has: accNum (int) Balance (double) ● a constructor four methods: o deposit() withdraw() O o getAccNum() o getBalance() Implement a…arrow_forward
- Programming in Java. What would the difference be in the node classes for a singly linked list, doubly linked list, and a circular linked list? I attached the node classes I have for single and double, but I feel like I do not change enough? Also, I use identical classes for singular and circular node which does not feel right. Any help would be appreciated.arrow_forwardDevelop classes STint and STdouble for maintaining ordered symbol tables where keys are primitive int and double types, respectively. (Convert genericsto primitive types in the code of RedBlackBST.) Test your solution with a version ofSparseVector as a client.arrow_forwardpresentation: Show how to use the diamond operator when creating instances of generic classes in javaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education