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)
- Focus on classes, objects, methods and good programming style Your task is to create a BankAccount class. Class name BankAccount Attributes _balance float _pin integer Methods init () get_pin() check pin () deposit () withdraw () get_balance () The bank account will be protected by a 4-digit pin number (i.e. between 1000 and 9999). The pin should be generated randomly when the account object is created. The initial balance should be 0. get_pin () should return the pin. check_pin (pin) should check the argument against the saved pin and return True if it matches, False if it does not. deposit (amount) should receive the amount as the argument, add the amount to the account and return the new balance. withraw (amount) should check if the amount can be withdrawn (not more than is in the account), If so, remove the argument amount from the account and return the new balance if the transaction was successful. Return False if it was not. get_balance () should return the current balance.…arrow_forwardjava When we create an object of a class, the object's instance variables are automatically initialized with its default values without us writing code in any constructor. Choose one of the options:TrueFalsearrow_forwardPyhton Code: Create a Pizza class which stores information about a single pizza. It contains the following: -Instance variables to store the size of the pizza (small, medium or large), (1)the number of cheese toppings, (2)the number of pepperoni toppings, and the (3) number of mushroom toppings. - Constructor: that takes four arguments and sets all of the corresponding instance variables and that initializes all instance variables to the zero of their type. - Methods to get (accessor) and set (mutator) each instance variable individually. - A method called calcCost() that returns the cost of the pizza. Pizza cost is determined by: Small: $10 + $2 per topping Medium: $12 + $2 per topping Large: $14 + $2 per topping. -A method which returns a string for the pizza size, quantity of each topping, and the pizza cost as calculated by the following example, a large pizza with 1 cheese, 2 pepperoni and 1 mushroom toppings should cost $22 (you can overwrite __str__).arrow_forward
- Lab 2 – Designing a class This lab requires you to think about the steps that take place in a program by writing pseudocode. Read the following program prior to completing the lab. Design a class named Computer that holds the make, model, and amount of memory of a computer. Include methods to set the values for each data field, and include a method that displays all the values for each field. For the programming problem, create the pseudocode that defines the class and enter it below. Enter pseudocode herearrow_forwardclass Student(object): """Represents a student.""" def __init__(self, name, number): """All scores are initially 0.""" self._name = name self._scores = [] for count in range(number): self._scores.append(0) def getName(self): """Returns the student's name.""" return self._name def setScore(self, i, score): """Resets the ith score, counting from 1.""" self._scores[i - 1] = score def getScore(self, i): """Returns the ith score, counting from 1.""" return self._scores[i - 1] def getAverage(self): """Returns the average score.""" return sum(self._scores) / len(self._scores) def getHighScore(self): """Returns the highest score.""" return max(self._scores) def __str__(self): """Returns the string representation of the student.""" return "Name: " + self._name + "\nScores: " + \ " ".join(map(str, self._scores))arrow_forwardCould you please help me with this chapter 6 number 15 Programming challenge from Starting out with Java Gaddis 7th edition book. Thank youarrow_forward
- class City(object): county = "Lake" population = 3000000 def -_init__(self, name, state): self.name = name self.state = state def region(self): return "Midwest" a) create an instance of this object, called X, for Chicago, Illinois b) return the population of the instance X c) change the county of the instance X from Lake to Cook d) return the name of the state of the instance X d) call the method region() on the instance Xarrow_forwardAssignment: 1- Create a class called Book with the following attributes: 1. title: The title of the book. 2. author: The author of the book. 3. pages: The number of pages in the book. Use a constructor (__init___) to initialize these attributes when creating an object from the class. Add a method inside the class calle description() which returns a description of the book Lec 3: Classes and Objects Object-oriented programming 2- Create a class called Phone with the following attributes: 1. brand: The brand of the phone. 2. price: The price of the phone. Use a constructor (__init__) to initialize these attributes when creating an object from the class. Add a method inside the class called show_info(), which prints the phone's detailsarrow_forwardAn interface is a collection of _______ that a class can implementarrow_forward
- The term "instance" refers to a member of a class.arrow_forwardT/F: Instance variables are shared by all the instances of the class. T/F: The scope of instance and static variables is the entire class. They can be declared anywhere inside a class. T/F: To declare static variables, constants, and methods, use the static modifier.arrow_forwardFocus on classes, objects, methods and good programming style Your task is to create a BankAccount class(See the pic attached) The bank account will be protected by a 4-digit pin number (i.e. between 1000 and 9999). The pin should be generated randomly when the account object is created. The initial balance should be 0. get_pin()should return the pin. check_pin(pin) should check the argument against the saved pin and return True if it matches, False if it does not. deposit(amount) should receive the amount as the argument, add the amount to the account and return the new balance. withraw(amount) should check if the amount can be withdrawn (not more than is in the account), If so, remove the argument amount from the account and return the new balance if the transaction was successful. Return False if it was not. get_balance() should return the current balance. Finally, write a main() to demo your bank account class. Present a menu offering a few actions and perform the action the user…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage