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
Question
Chapter 15.5, Problem 15.5.1CP
Program Plan Intro
Inner class:
- When a class is defined within the scope of another class then the class is called as inner class or nested class.
- Inner class objects are being created in the outer class.
- An inner class can also be used as a regular class.
- A class is defined to be a nested class only if it is used by its outer class.
Anonymous inner class:
- It is other inner class in the inner class that is defined without a name.
- It is used to the combine the process defining and instance creation of the class in one single step.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Using the scenario of Object oriented programming
Q1 Write a program that defines a class with a data member to holds a “serial number” for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this, you’ll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each about its serial number. They should respond I am object number 2, and so on.
Please explain, in light of the aforementioned three reasons, why it is preferable to have accessors for private types as opposed to making them public.
If a member is declared private in a class, can it be accessed from other classes? If a member is declared protected in a class, can it be accessed from other classes? If a member is declared public in a class, can it be accessed from other classes?
Chapter 15 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 15.2 - Prob. 15.2.1CPCh. 15.2 - Prob. 15.2.2CPCh. 15.3 - Why must a handler be an instance of an...Ch. 15.3 - Explain how to register a handler object and how...Ch. 15.3 - Prob. 15.3.3CPCh. 15.3 - What is the registration method for a button to...Ch. 15.4 - Can an inner class be used in a class other than...Ch. 15.4 - Can the modifiers public, protected, private, and...Ch. 15.5 - Prob. 15.5.1CPCh. 15.5 - What is wrong in the following code?
Ch. 15.6 - Prob. 15.6.1CPCh. 15.6 - What is a functional interface? Why is a...Ch. 15.6 - Prob. 15.6.3CPCh. 15.8 - Prob. 15.8.1CPCh. 15.8 - Prob. 15.8.2CPCh. 15.9 - Prob. 15.9.1CPCh. 15.9 - Prob. 15.9.2CPCh. 15.9 - Prob. 15.9.3CPCh. 15.9 - If the following code is inserted in line 57 in...Ch. 15.10 - Prob. 15.10.1CPCh. 15.11 - Prob. 15.11.1CPCh. 15.11 - Prob. 15.11.2CPCh. 15.11 - Prob. 15.11.3CPCh. 15.11 - Prob. 15.11.4CPCh. 15.12 - How does the program make the ball appear to be...Ch. 15.12 - How does the code in Listing 15.17, BallPane.java,...Ch. 15.12 - What does the program do when the mouse is pressed...Ch. 15.12 - If line 32 in Listing 15.18, BounceBall.java, is...Ch. 15.12 - Prob. 15.12.5CPCh. 15.13 - Prob. 15.13.1CPCh. 15.13 - What would happen if map is replaced by scene in...Ch. 15.13 - Prob. 15.13.3CPCh. 15 - Prob. 15.1PECh. 15 - (Rotate a rectangle) Write a program that rotates...Ch. 15 - (Move the ball) Write a program that moves the...Ch. 15 - (Create a simple calculator) Write a program to...Ch. 15 - (Create an investment-value calculator) Write a...Ch. 15 - (Alternate two messages) Write a program to...Ch. 15 - (Change color using a mouse) Write a program that...Ch. 15 - (Display the mouse position) Write two programs,...Ch. 15 - (Draw lines using the arrow keys) Write a program...Ch. 15 - (Enter and display a string) Write a program that...Ch. 15 - (Move a circle using keys) Write a program that...Ch. 15 - Prob. 15.12PECh. 15 - (Geometry: inside a rectangle?) Write a program...Ch. 15 - Prob. 15.14PECh. 15 - Prob. 15.15PECh. 15 - (Two movable vertices and their distances) Write a...Ch. 15 - (Geometry: find the bounding rectangle) Write a...Ch. 15 - Prob. 15.18PECh. 15 - (Game: eyehand coordination) Write a program that...Ch. 15 - Prob. 15.20PECh. 15 - (Drag points) Draw a circle with three random...Ch. 15 - (Auto resize cylinder) Rewrite Programming...Ch. 15 - Prob. 15.23PECh. 15 - Prob. 15.24PECh. 15 - Prob. 15.25PECh. 15 - Prob. 15.26PECh. 15 - Prob. 15.27PECh. 15 - (Display a running fan) Write a program that...Ch. 15 - (Racing car) Write a program that simulates car...Ch. 15 - Prob. 15.30PECh. 15 - Prob. 15.31PECh. 15 - (Control a clock) Modify Listing 14.21,...Ch. 15 - (Game: bean-machine animation) Write a program...Ch. 15 - Prob. 15.34PECh. 15 - Prob. 15.35PECh. 15 - Prob. 15.36PE
Knowledge Booster
Similar questions
- What is the accessibility of a protected attribute that is in a public class? A. Any class has access to this attribute. B. Only the class and its subclasses have access to this attribute. C. Only the class itself has access to this attribute. D. Any class in the same package has access to this attribute.arrow_forwardWhat happens to serialized objects created with an earlier version of the class specification if an additional field is added?arrow_forwardI need some help with this coding problemarrow_forward
- What is a characteristic of static members? a. For every object created, there is only one field and/or method used by all copies. b. From another class, static methods are called by using the object reference only. c. Static members are implied when declared without the word static. O d. Within the same class, static fields can call instance methods.arrow_forwardCreate a Person class for a user of the system. Create person.h and person.cpp files for this class.The class should contain the following data of a person in the system:• first name,• last name,• user ID, and• email address.These data should be accessible in its derived class. (Consider should the data be private, public,or protected?)This class should contain:• a default constructor,• a value constructor that receives all of the data to be placed into the data members as itsparameters,• a copy constructor.The class should also contain:• “get” methods to allow the client to obtain information about a person.o getFirstName, getLastName, getID, getEmail• “set” methods to allow the client to assign information to a seller.o setFirstName, setLastName, setID, setEmail, and optionally setAllInfo• overloaded operatorso overloaded == method that returns true if two sellers have identical names andemail address; otherwise it returns false.o overloaded !=, <, and > operators (for > and…arrow_forwardExplain why it is preferable to have accessors to private types rather than making the types public, keeping in mind the three reasons that are given below.arrow_forward
- Question 5: 1. Explain how the Dealer class can maintain record of multiple cars using minimal code. 2. Write an addCar() method that receives a Car object and adds it to the Dealer class. 3. Write a contains method that takes the name of a Car and determines whether the Dealer has that Car in its collection. 4. Write part of the code that removes the car from the dealer class that is sold.arrow_forwardClasses - Continued... Write a definition of a class and write a program that implements all the functionality of the class that has the following properties. The Main Program should invoke all functionality of this class, i.e., secretType. Input: from a file - the person's name and age and weight and height Output: The Original input and based on their BMI, their weight status. The name of the class is secretType. a. The class secretType has four member variables: name (a string), age and weight (int), height (double) b. The class secretType has the following member functions: (Make the accessor functions const) с. i. print – outputs the data in the member variables in a nicely formatted ii. setName - sets the name iii. setAge – sets the age iv. setWeight – sets the weight setHeight – sets the height V. vi. getName – value returning function returns the name vii. getAge – value returning function returns the age viii. getHeight – value returning function returns the height ix.…arrow_forwardWrite a C++ program that defines a class with a data member to holds a “serial number” for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this, you’ll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each about its serial number. They should respond I am object number 2, and so on.arrow_forward
- Problem You want to implement a custom class that mimics the behavior of a common built-in container type, such as a list or dictionary. However, you're not entirely sure what methods need to be implemented to do it.arrow_forwardPlease see attached.arrow_forwardWrite a class Employee with data members Name, Id, and Salary. Derive two classes, Faculty with data members Department, and role(permanent or visiting) and derived class Management with data members Department and rank (manager, deputymanager, etc.). Create getters,settersfor all thedata members, create constructors,destructors and show functions for all the classes.Create a write function to write employees on a file . In main function create two objects of each derived class using parameterized constructors, call the show function to show all four objects, write all four objects to a file. Your submission should include the output file.arrow_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