Explanation of Solution
Instance creation without providing type argument:
“Yes”, the instances of generic class can be created without providing type argument.
Explanation:
- Instance creation of a generic class is possible without providing the type argument.
Example:
// Create generic class exam with type parameter T
public class exam<T>
{
//Declare the variable with type parameter T
private T to;
private T ra;
//Define the generic class constructor
public exam(T tot, T rank)
{
//Assigning values for variable
to= tot;
ra=rank;
}
//Define the main method
public static void main (String[] args)
{
//Create the Integer object
Integer rank= new Integer(2);
//Create Double object
Double tot= new Double(466...
Explanation of Solution
Recommendation:
“No”, it is not recommended, even the instance of a generic class can be created without providing the type argument.
Explanation:
- Instance creation of a generic class is possible without providing the type argument.
Example:
// Create generic class exam with type parameter T
public class exam<T>
{
//Declare the variable with type parameter T
private T to;
private T ra;
//Define the generic class constructor
public exam(T tot, T rank)
{
//Assigning values for variable
to= tot;
ra=rank;
}
//Define the main method
public static void main (String[] args)
{
//Create the Integer object
Integer rank= new Integer(2);
//Create Double object
Double tot= new Double(466...
Want to see the full answer?
Check out a sample textbook solutionChapter 18 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- Dynamic Apex: Write test class for this apex code(Not required the output) You are working on the project in which you have to create the apex code in which your task is to define the objects dynamically by using the method argument which is api name in string and a map of string, string as a key value pair. Class Code: public static void modifySobjectData(String str , Map mapofString) { //Retrive the type of Sobject by using the getGlobalDescribe Schema.SobjectType targetType = Schema.getGlobalDescribe().get(str); //Initalize the Object Sobject newobject = targetType.newSobject(); for (String s :mapofString.keySet() { newobject.put(s, mapofString.get(s)); } System.debug('newObject' + newobject); //Perform the DML if(targetType != null) insert newobject; } }arrow_forwardWhy do we use generic classes? Generic classes allows for code reuse (for different data types) Generic classes allows for the Object class (the generic data type) to be used as a field Generic classes allow for abstract class (of which there can be no instantiations) to be used as a field The compiler will automatically generate test cases based on the appropriate data typesarrow_forwardDescription: Create a class named ComparableDog that extends Animal and implements Comparable interface. Implement the compareTo method to compare the Dogs on the basis of age. Write a test class to find the bigger age of two instances of ComparableDog Objects, and complement the ComparableDog class with the missing part. 1) The test program, the ComparableDog class, and its super class Animal are given as follows. // Main method public static void main(String[] args) { // Create two comparable Dogs ComparableDog dog1 = new ComparableDog(3); ComparableDog dog2 = new ComparableDog(4); System.out.println("Dog1:" + dog1); System.out.println("Dog2:" + dog2); if(dog1.compareTo(dog2) == 1) System.out.println("Dog1 is older than Dog2"); else if(dog1.compareTo(dog2) == -1) System.out.println("Dog1 is younger than Dog2"); else System.out.println("Dog1 and Dog2 have the same age"); }…arrow_forward
- How can you prevent the derived class from accessing methods from the base class?arrow_forwardHow we can access protected data members of a class without the use of public or private functions? Explain with codearrow_forwardLanguage: C++ Next a thirst level (as double value) should be added to the properties of a critter. Add a new constructor that takes five parameters for setting all properties of a critter. Make also sure that the existing constructors will still work. For the existing constructors, the thirst level should be set to the same level as the hunger level. Your existing testcritter.cpp must still be able to run in its unchanged form. So the already existing constructors need to support the change. Name the files Critter.h, Critter.cpp and testcritter.cpp. Finally, you should adapt the print method for printing on the screen also the value of the thirst level as a double. The client program testcritter.cpp may contain one additional line, where the constructor taking five parameters is being called. You can assume that the setting values are always valid.arrow_forward
- Software Requirements: • Latest version of NetBeans IDE • Java Development Kit (JDK) 8 Procedure: 1. our progras from rhFactor non-static and private. Remove the constructor with two (2) parameters. 2o upply uncapsutation Make bloodType and 2. The names of the public setter and getter methods should be: • setBloodType() • setRhFactor() getBlood Type() getRhFactor() 3. Use the setter methods to accept user input. 4. Display the values by calling the getter methods. Sample Output: Enter blood type of patient: Enter the Rhesus factor (+ or -): O+ is added to the blood bank. Enter blood type of patient: B Enter the Rhesus factor (+ or -): B- is added to the blood bank.arrow_forwardSo, what are "static members" of a class, exactly? When and why should you take use of them?arrow_forwardProblem C • -3: method consonants() had more than one loop • -3: method initials () had more than one loop • -3: at least one method used nested loopsarrow_forward
- 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