Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 11.9, Problem 11.9.1CP
Indicate true or false for the following statements:
a. You can always successfully cast an instance of a subclass to a superclass.
b. You can always successfully cast an instance of a superclass to a subclass.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Answer with True or False for the following. Explain your answers.-It is legal to write a method in a class which overloads another method declared in the same.-It is legal to write a method in a superclass which overrides a method declared in a sub-class.
a.) Write the definition of the default constructor of YClass so that the instance variables of YClasa are initialized to 0.
b.) Write the definition of the default constructor of XClass so that the instance variable of XClass are initialized to 0.
c.) Write the definition of the method two of YClass so that rhe instance variable a is initialized to the value of the first parameter of two, and the instance variable b is initialized to the value of the second parameter of two.
What is the process of defining a method in a
subclass having same name & type signature as
a method in its superclass?
a) Method overloading b) Method overriding
c) Method hiding d) None of the mentioned
Chapter 11 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 11.2 - True or false? A subclass is subset of a...Ch. 11.2 - What keyword do you use to define a subclass?Ch. 11.2 - What is single inheritance? What is multiple...Ch. 11.3 - What is the output of running the class C in (a)?...Ch. 11.3 - How does a subclass invoke its superclasss...Ch. 11.3 - True or false? When invoking a constructor from a...Ch. 11.4 - True or false? You can override a private method...Ch. 11.4 - True or false? You can override a static method...Ch. 11.4 - How do you explicitly invoke a superclasss...Ch. 11.4 - How do you invoke an overridden superclass method...
Ch. 11.5 - Identify the problems in the following code:...Ch. 11.5 - Prob. 11.5.2CPCh. 11.5 - If a method in a subclass has the same signature...Ch. 11.5 - If a method in a subclass has the same signature...Ch. 11.5 - If a method in a subclass has the same name as a...Ch. 11.5 - Prob. 11.5.6CPCh. 11.7 - Prob. 11.7.1CPCh. 11.8 - Prob. 11.8.1CPCh. 11.8 - Prob. 11.8.2CPCh. 11.8 - Can you assign new int[50], new Integer [50], new...Ch. 11.8 - Prob. 11.8.4CPCh. 11.8 - Show the output of the following code:Ch. 11.8 - Show the output of following program: 1public...Ch. 11.8 - Show the output of following program: public class...Ch. 11.9 - Indicate true or false for the following...Ch. 11.9 - For the GeometricObject and Circle classes in...Ch. 11.9 - Suppose Fruit, Apple, Orange, GoldenDelicious, and...Ch. 11.9 - What is wrong in the following code? 1public class...Ch. 11.10 - Prob. 11.10.1CPCh. 11.11 - Prob. 11.11.1CPCh. 11.11 - Prob. 11.11.2CPCh. 11.11 - Prob. 11.11.3CPCh. 11.11 - Prob. 11.11.4CPCh. 11.11 - Prob. 11.11.5CPCh. 11.12 - Correct errors in the following statements: int[]...Ch. 11.12 - Correct errors in the following statements: int[]...Ch. 11.13 - Prob. 11.13.1CPCh. 11.14 - What modifier should you use on a class so a class...Ch. 11.14 - Prob. 11.14.2CPCh. 11.14 - In the following code, the classes A and B are in...Ch. 11.14 - In the following code, the classes A and B are in...Ch. 11.15 - Prob. 11.15.1CPCh. 11.15 - Indicate true or false for the following...Ch. 11 - Sections 11.211.4 11.1(The Triangle class) Design...Ch. 11 - (Subclasses of Account) In Programming Exercise...Ch. 11 - (Maximum element in ArrayList) Write the following...Ch. 11 - Prob. 11.5PECh. 11 - (Use ArrayList) Write a program that creates an...Ch. 11 - (Shuffle ArrayList) Write the following method...Ch. 11 - (New Account class) An Account class was specified...Ch. 11 - (Largest rows and columns) Write a program that...Ch. 11 - Prob. 11.10PECh. 11 - (Sort ArrayList) Write the following method that...Ch. 11 - (Sum ArrayList) Write the following method that...Ch. 11 - (Remove duplicates) Write a method that removes...Ch. 11 - (Combine two lists) Write a method that returns...Ch. 11 - (Area of a convex polygon) A polygon is convex if...Ch. 11 - Prob. 11.16PECh. 11 - (Algebra: perfect square) Write a program that...Ch. 11 - (ArrayList of Character) Write a method that...Ch. 11 - (Bin packing using first fit) The bin packing...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What are the advantages and disadvantages of implicit declarations?
Concepts Of Programming Languages
Determine the tension in these wires.
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
What is the purpose of an objects sizing handles?
Starting Out With Visual Basic (8th Edition)
On paper, write a program that will display your name on the first line; your street address on the second line...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
The following algorithm is designed to print the beginning of what is known as the Fibonacci sequence. Identify...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Write a program that converts degrees from Fahrenheit to Celsius, using the formula DegreesC = 5(DegreesF - 32)...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- True or false?(a) You can override a nonprivate method defined in a superclass.(b) You can override a private method defined in a superclass.(c) You can override the initializer defined in a superclass. (d) When constructing an object from a subclass, its superclass’s initializer is automatically invoked.arrow_forward- Creates a class Teacher with two attributes: name and specialty. a. Add a constructor able to create a Teacher; b. Add the methods getName and getSpeciality; c. Add the method display able to display the attributesarrow_forwardDesign/code/test a Java program containing an abstract the class absWelcome. This class should contain: 1. A public abstract void method (you name it) that is empty 2. A public regular method (you name it) that prints "Welcome to " Next, create a subclass clsHello that extends absWelcome. This class should contain: • A public regular method (you name it) that prints "Java Programming" Finally, inside the Main class create an object (you name it) from the clsHello class. Use this new object reference to: 1. Output "Welcome to " from the abstract class 2. Output "Java Programming" from the subclass Your output should resemble that shown below >sh -c javac -classpath -type f-name '*.java') java -classpath :targe Welcome to Java Programmingarrow_forward
- Language is Java Write a Clothing class with the following attributes: color (e.g., "blue", "green", "orange") displayName (e.g., "Doctor Who hoodie", "slacks") price (e.g., 19.99, 7) Include only one constructor. It should have parameters for each of the attributes and set their values. Additionally, include getters and setters for each of the attributes. Add a driver, name it Purchases, and create 2 Clothing objects. Finally, print out some information about both objects (i.e., print the information from some or all of the getters). For example, if you created a Clothing object whose color was blue, whose display name was work trousers, for a price of 27.99, you could use the getters to print something like this:These work trousers are blue and cost $27.99.Don't hardcode the print statement for full credit, you must use the gettersarrow_forwardFor each statement, indicate if it is True or False by circling T or F. If you need to cross out an answer, be sure that your final answer is clear and unambigous-otherwise it will receive no credit. 1- An object of a derived class has access to the public methods of its base class T F 2- An object of a base class has access to the private helper methods of its derived class T F 3- Destructors are not inherited by derived classes T F T F T F u- An object of a derived class inherits the copy constructor of its base class 5- Operators are passed down inheritance hierarchies 6- Destructors in derived classes are called after their base class calls its destructor 7. Constructors of base classes are accessible by derived classes T T F Farrow_forwardAssignment: Write the class XXXX_Worker with constructors, accessors, mutuators, and a toString method. A Worker has a Worker Name and Number. Write the class XXXX_ProductionWorker which is a subclass of Worker. The production worker has a shift number (values: 1 or 2) and an Hourly pay rate. A shift number of 1 means the day shift and 2 means the night shift. Write the class XXXX_ShiftSupervisor which is a subclass of Worker. The shift supervisor is a salaried worker who supervises a shift. The shift supervisor has a yearly bonus field. The yearly bonus is earned at year end based on performance. Write a class, XXXX_TestWorker, which does the following: Creates one Shift Supervisor object from information entered by the user. Creates an Array of Production Workers that can hold 3 objects. Itcreates3ProductionWorkerobjectsfrominformationenteredbytheuser Prints the information about each object in the format shown below using the toString methods of the…arrow_forward
- Classes and Objects) Hand-write a complete Java class that can be used to create a Car object as described below. a. A Vehicle has-a: i. Registration number ii. Owner name iii. Price iv. Year manufactured b. Add all instance variables C. The class must have getters and setters for all instance variables d. The class must have two constructors, a no-args and a constructor that receives input parameters for each instance variable.arrow_forward2019 AP® COMPUTER SCIENCE A FREE-RESPONSE QUESTIONS 2. This question involves the implementation of a fitness tracking system that is represented by the StepTracker class. A StepTracker object is created with a parameter that defines the minimum number of steps that must be taken for a day to be considered active. The StepTracker class provides a constructor and the following methods. addDailySteps, which accumulates information about steps, in readings taken once per day activeDays, which returns the number of active days averageSteps, which returns the average number of steps per day, calculated by dividing the total number of steps taken by the number of days tracked The following table contains a sample code execution sequence and the corresponding results. Statements and Expressions Value Returned Comment (blank if no value) StepTracker tr StepTracker(10000); Days with at least 10,000 steps are considered active. Assume that the parameter is positive. new tr.activeDays () ; No…arrow_forward1 - Student class Make a class student (in student.py) that stores the following information for a student: Name (name) Student number (student_nr) Points per assignment (points_per_assignment) Exam grade (exam_grade) a) Behind each point of information is the name of the parameter to the initializer method. Store this information from the parameters in the object attributes with the same name. b) Add a method course_points() which returns the number of course points the student has gotten. Example: mary = Student("Mary", 15789613, [10, 9, 8, 10, 9, 10], 9)print(mary.course_points()) > 121 The calculation of the course points is explained in the course overview, course setup slides (Links to an external site.) and the first lectureLinks to an external site.. c) Add a method grade() which returns a the final grade of the student, rounded to nearest half (upwards, 6.75 -> 7). As per regulations, a 5.5 becomes a 6. If the student did not pass both the assignments (>= 95…arrow_forward
- Python Code: Write a class called Person with a constructor that takes two arguments, name and age and the saves these as attributes Write a method in this called print_person that prints out this information the console Confirm that you did it properly by instantiating an object called p1 and calling the method on the object. Lastly, extend the constructor by adding functionality that checks the input name only contains letters (no numbers allowed).arrow_forwardWhat is the main difference between a struct and a class? (More than 1 answer can be chosen)arrow_forwardWhich of the following statements are true. a) An abstract method contains a signature but no code implementation. b) We cannot create an instance of an abstract class by using the new operator. c) We can derive classes from an abstract class, but we must provide code to implement all of the abstract methods. d) All of the above statements are true.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY