Concept explainers
Each object that is created from a class is called a(n)_______ of the class.
- a. reference
- b. example
- c. instance
- d. event
An instance of a class refers to each object created from a class.
Hence, the correct answer is option “C”.
Explanation of Solution
Instance of a class:
- • A class is defined as a group of user defined data structure that consists of fields, properties, and methods that can perform several operations for all instances of the class.
- • A class acts as a declaration of a real world entity.
- • An object of a class cannot be directly created until it has its own properties and methods.
- • When an instance of a class is created, a separate memory block is being created in the memory.
- • A class is a blue-print which describes how an instance of the class is created.
Explanation for incorrect options:
Reference:
To pass the instance of a class to a method parameter, a reference is used.
Hence, the option “A” is wrong.
Example:
Example contains the real time information regarding an event.
Hence, the option “B” is wrong.
Event:
An event is defined as a specific task performed to attain a target output.
Hence, the option “D” is wrong.
Want to see more full solutions like this?
Chapter 9 Solutions
Starting out with Visual C# (4th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Database Concepts (8th Edition)
- a. Create a class named Invoice that contains fields for an item number, name, quantity, price, and total cost. Create instance methods that set the item name, quantity, and price. Whenever the price or quantity is set, recalculate the total (price times quantity). Also include a displayLine() method that displays the item number, name, quantity, price, and total cost. Save the class as Invoice.java. b. Create a class named TestInvoice whose main() method declares three Invoice items. Create a method that prompts the user for and accepts values for the item number, name, quantity, and price for each Invoice. Then display each completed object. Save the application as TestInvoice.java.arrow_forwardCreate a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four information as instance variables: a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0.0. Write a tester class named InvoiceTest that demonstrates class Invoice’s capabilities by creating two invoices then changing and printing their characteristics.arrow_forwardCreate a class Car with parameters companyName, color, maxSpeed (Not more than 150) andcategory. Use appropriate data types and access specifiers. Use default constructor to create objectsof cars. (JAVA)arrow_forward
- Create an Inventory class named, Inventory.cpp, that can hold information and calculatedata for items in a retail store’s inventory.The class should have the following private member variables:Variable Name DescriptionitemNumber An integer that holds the item’s item number.quantity An integer for holding the quantity of the items on hand.cost A double for holding the wholesale per-unit cost of the itemtotalCost A double for holding the total inventory cost of the item(calculated as quantity times cost).The class should have the following public member functions:Member Function DescriptionDefault Constructor Sets all the member variables to 0.Constructor #2 Accepts an item’s number, cost, and quantity as arguments.The function should copy these values to the appropriatemember variables.setItemNumber Accepts an integer argument that is copied to theitemNumber member variable.setQuantity Accepts an integer argument that is copied to the quantitymember variable.setCost Accepts a double…arrow_forwardCreate an Inventory class named, Inventory.cpp, that can hold information and calculatedata for items in a retail store’s inventory.The class should have the following private member variables:Variable Name DescriptionitemNumber An integer that holds the item’s item number.quantity An integer for holding the quantity of the items on hand.cost A double for holding the wholesale per-unit cost of the itemtotalCost A double for holding the total inventory cost of the item(calculated as quantity times cost).The class should have the following public member functions:Member Function DescriptionDefault Constructor Sets all the member variables to 0.Constructor #2 Accepts an item’s number, cost, and quantity as arguments.The function should copy these values to the appropriatemember variables.setItemNumber Accepts an integer argument that is copied to theitemNumber member variable.setQuantity Accepts an integer argument that is copied to the quantitymember variable.setCost Accepts a double…arrow_forwardCreate an Inventory class named, Inventory.cpp, that can hold information and calculatedata for items in a retail store’s inventory.The class should have the following private member variables:Variable Name DescriptionitemNumber An integer that holds the item’s item number.quantity An integer for holding the quantity of the items on hand.cost A double for holding the wholesale per-unit cost of the itemtotalCost A double for holding the total inventory cost of the item(calculated as quantity times cost).The class should have the following public member functions:Member Function DescriptionDefault Constructor Sets all the member variables to 0.Constructor #2 Accepts an item’s number, cost, and quantity as arguments.The function should copy these values to the appropriatemember variables.setItemNumber Accepts an integer argument that is copied to theitemNumber member variable.setQuantity Accepts an integer argument that is copied to the quantitymember variable.setCost Accepts a double…arrow_forward
- java Create Class (any class) that include: Three variables Name ( default value is your name ) Id ( default value is your Id ) Print Method. Create parameterized constructor for that class and initialize it with your name and your id, try to use this keyword ? 3 create an object to that class and pass (1234, Dana) as parameters Ps : write your code in eclipse and send it as screen shotarrow_forwardCreate a constructor for the Student class you created. The constructor should initialize each Student’s ID number to 9999, his or her points earned to 12, and credit hours to 3 (resulting in a grade point average of 4.0). Write a program that demonstrates that the constructor works by instantiating an object and displaying the initial values. Save the application as ShowStudent2.java.arrow_forwardPart A Create a class named Apartment that holds an apartment number as aptNumber, number of bedrooms as bedrooms, number of baths as baths, and rent amount as rent. Create a default constructor that accepts no arguments and an overloaded constructor that accepts values for each data field. Also create a get method for each field. Part B Write an application called TestApartments that creates at least five Apartment objects. Then prompt a user to enter a minimum number of bedrooms required, a minimum number of baths required, and a maximum rent the user is willing to pay. Display data for all the Apartment objects that meet the user’s criteria or an appropriate message if no such apartments are available. An example of the program is shown below: Enter minimum number of bedrooms needed >> 2 Enter minimum number of bathrooms needed >> 1.5 Enter maximum rent willing to pay >> 1200 Apartments meeting criteria of at least 2 bedrooms, at least 1.5 baths, and no more than…arrow_forward
- Each object that is created from a class is called a(n) __________ of the class. a. reference b. example c. instance d. eventarrow_forwardCreate a class called Person that will hold information about a single individual. This class should have a data section that consists of the following: Variable Name Data Type firstName string lastName string address string The Person class should have the following mutators: setFirstName(string first); setLastName(string last); setAddress(string address); The Person class should have the following accessors: string getFirstName(); string getLastName(); string getAddress(); The Person class should have the following constructors: Person(); - default Person(string first, string last); - Set other fields to an empty string Person(string first, string last, string address); Note: You must use delegating constructors to eliminate duplicate code. Main Create an array which will hold 5 Person classes. Pass the array to a function called getPeople which will fill out the array with information about people taken from the keyboard. Create a…arrow_forwardCreate a class called Student to represent a Student exam grades. The class has four instance variables: A String variable for the name, and three double variables to store three exams grades for the student. Write a mutator method that takes four parameters—A String and three doubles. Use these parameters to initialize the instance variables declared earlier. Write a getAverage method that calculates and returns the average of the three exam grades. Write a separate program that creates 2 Student objects to hold the following data. First Name Exam#1 Exam#2 Exam#3 Ahmed 83.0 95.5 90.0 Kareema 75.25 83.0 89.0 Output the name and average grade for each of the above students.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT