CS Ch 5

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following is true of mutable and immutable data types used in a function?

Passing an instance of a class into a function changes the mutable variables of the class whereas passing only the immutable variables into a function does not Operations done on mutable data types propagate out of the function whereas operations done on immutable data types do not

getter

A common type of method in writing classes that returns the value of a variable contained within the class. They are commonly used to allow other processing to occur whenever the variable is accessed, like logging.

setter

A common type of method in writing classes that sets a variable contained within the class to a new value. They are commonly used to allow other processing to occur whenever the variable is changed, like logging.

Destructor:

A common type of method in writing classes that specifies how the instance of a class is to be destroyed, such as releasing its memory back to the computer.

Constructor:

A common type of method in writing classes that specifies some code to run whenever a new instance of the class is created. The constructor often has parameters that provide values to initialize the variables defined by the class.

Class

A custom data type comprised of multiple variables and/or methods. Instances or objects are created based on the template provided by the class.

Abstraction

A principle of object-oriented programming that states that only essential information should be made visible to the outside program.

Inheritance

A principle of object-oriented programming where classes can be created that are "subclasses" of other classes, inheriting all the variables and methods from the other class while supplying new variables, methods, or behaviors of these own.

Object-oriented programming

A programming paradigm where programmers define custom data types that have custom methods embedded within them

Instance

A single set of values of a particular class. Classes may be comprised of multiple variables; an instance is a set of values for these variables. The term "instance" is often used interchangeably with the term "object".

Object

An object is a custom data structure that organizes and encapsulates variables and methods into a single data type. It is used near-interchangeably with "instance."

So a constructor is a method that is automatically run whenever you create a new instance of a class.

Any code you want to run before the instance can be used should be placed inside the constructor.

Identify a benefit of using dictionaries over classes

Dictionaries can define multiple variables in one line

Which of the following are benefits to using getters and setters even in languages where they are not required for accessing variables inside an instance?

Getters and setters let us log whenever a variable's value is accessed or changed. Getters and setters let us prevent unauthorized access to instance variables' values. Getters and setters let us build customized ways for modifying or retrieving instance variables' values.

Consider two classes: Furniture and chair. The furniture class has three variables: color, material, and weight. The chair class has five variables: color, material, weight, armrest, and type. Which of the following object-oriented principles is exhibited by these two classes?

Inheritance

Which of the following are advantages of encapsulation?

It helps avoid the misuse of data by other functions or programs It helps avoid the modification of data by other functions

A class named Person is declared with three class members called name, age, and eye color. The variable Person1 of type Person is declared with the name "Sara Williams", age 30, and eye color brown. What can be inferred about classes, instances, and objects

Sara Williams is an instance of an object named Person1 with the name "Sara Williams" age 30 and eye color brown Classes are the general description of the types of variables associated with the type, whereas an instance is the set of values for these variables.

Encapsulation:

The ability to combine variables and methods into class definitions in object-oriented programming. It helps avoid modification or misuse of data by other functions or programs.

Polymorphism

The principle that a method call can behave differently depending on the arguments and object with which it is called.


Set pelajaran terkait

Common Ethical Issues Unit 2 Lesson One Personal versus Organizational Ethics

View Set

Physics 180B - Ch. 16-21 - Concepts (HW + Modules)

View Set

Cerebral Cortex (Sensory, Motor, Association)

View Set