Which method is invoked in a particular class when a method


1. Which method is invoked in a particular class when a method definition is overridden in several classes that are part of an inheritance hierarchy? Answer the question for the case in which the class has a definition for the method and also for the case where it doesn't.

2. Explain how assignments can be made within a class hierarchy and the role of casting in a class hierarchy. What is strong typing: Why is it an important language feature?

3. If Java encounters a method call of the following form:

superclassVar . met hodNarne

where superclassVar is a variable of a superclass that references an object whose type is a subclass, what is necessary for this statement to compile? During run time, will method methodName from the class that is the type of superclassVar always be invoked, or is it possible that a different method methodName will be invoked? Explain your answer.

4. Assume the situation in Question 3, but method methodName is not defined in the class that is the type of superclassVar, though it is defined in the subclass type. Rewrite the method call so that it will compile.

5. Explain the process of initializing an object that is a subclass type in the subclass con¬structor. What part of the object must be initialized first? How is this done?

6. 'What is the difference between the size and the capacity of an ArrayList? Why might we have a constructor that lets us set the initial capacity?

7. What is the difference between the remove (Object obj) and renove(int index) methods?

8. When we insert an item into an ArrayList, why do we start shifting at the last element?

9. The Vector and ArrayList both provide the same methods, since they both imple¬ment the List interface. The Vector has some additional methods with the same func¬tionality but different names. For example, the Vector addElement and add methods have the same functionality. There are some methods that are unique to Vector. Look at the Java API documentation and make a list of the methods that are in Vector that have equivalent methods in ArrayLi st and ones that are unique. Can the unique methods be implemented using the methods available in ArrayLi st?

10. If a loop processes n items and n changes from 1024 to 2048, how does that affect the running time of a loop that is 0(n2)? How about a loop that is 0(log n)? How about a loop that is 0(n log n)?

11. A veterinary office wants to store information regarding the kinds of animals it treats. Data includes diet, whether the animal is nocturnal, whether its bite is poisonous (as for some snakes), whether it flies, and so on. Use a superclass Pet with abstract methods and create appropriate subclasses to support about 10 animals of your choice.

12. A student is a person, and so is an employee. Create a class Person that has the data attributes common to both students and employees (name, social security number, age, gender, address, and telephone number) and appropriate method definitions. A student has a grade-point average (GM), major, and year of graduation. An employee has a department, job title, and year of hire. In addition, there are hourly employees (hourly rate, hours worked, and union dues) and salaried employees (annual salary). Define a class hierarchy and write an application class that you can use to first store the data for an array of people and then display that information in a meaningful way.

13. Develop a program to maintain a list of homework assignments. When an assignment is assigned, add it to the list, and when it is completed, remove it. You should keep track of the due date. Your program should provide the following services:
• Add a new assignment.
• Remove an assignment.
• Provide a list of the assignments in the order they were assigned.
• Find the assignment(s) with the earliest due date.

14. Write a program to manage a list of students waiting to register for a course as described in Section 2.5. Operations should include adding a new student at the end of the list, adding a new student at the beginning of the list, removing the student from the beginning of the list, and removing a student by name.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Which method is invoked in a particular class when a method
Reference No:- TGS01116283

Expected delivery within 24 Hours