Unit 3: Methods/Functions Continued Flashcards

1
Q

An Object is a combination of _____ and ______

A

Data, procedures

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Data in an object are known as…

A

attributes, fields, data members, or instance variables. An object stores data in its fields

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Procedures in an object are known as…

A

Methods, member-functions, member-methods, or method-members

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The first step in creating an object is to outline and define the characteristics of that object, with the aid of a _______

A

Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define: Class

A

A program structure that allows a programmer to define the characteristics of an object that needs to be created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A class may contain ______ only or ________ only

A

Methods, attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does object oriented programming (OOP) do?

A

Allows creating ‘objects’ and makes a program a cluster of interacting objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why the object-oriented approach?

A

Appropriate for programs that model the real world, accelerate system development, simplify systems integration and standardization, suitable for building huge applications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False: class is a keyword

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define: Access modifier

A

A Java keyword that indicates how a field, method, or class can be accessed in a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the three Java access modifiers:

A

Protected, public, private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

If there is no access modifier used, it is considered to have a _____ modifier

A

Default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define: public (access modifier)

A

Accessible from any class or package in the Java program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define: private (access modifier)

A

Accessible only within the class-definition. Outside a class, the private data-members and methods of that class can be accessed indirectly by the public methods of the same class via its objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define: protected (access modifier)

A

Allows for the data-members, methods, and constructors accessible in the same package and subclasses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Define: Default (access modifier)

A

Access from the same class and same package only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Classes that need to be used by other classes are typically made __________

A

Public

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Access modifier for any outer-class can be _____. Only inner-class can have ______ access modifier

A

Public, private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

True or False: In Java, an object is a reference-variable of a defined class type, also referred to as an instance of a class

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Since an object is an instance of a class, the non-static data-members/fields are also known as ________, while the non-static methods/function-members are known as ________

A

Instance variables, instance methods

21
Q

Demonstrate the syntax of object declaration in Java

A

ClassName referenceVariableName;

22
Q

True or False: An object reference-variable can be used before initialization

23
Q

Define: Encapslation

A

Enclosing the proper attributes and methods inside a single class

24
Q

What does encapsulation accomplish?

A

Ensures data-hiding and ensures the class is self-contained

25
Define: Getter methods (accessor methods)
The methods that retrieve/get the data-values of the field
26
Define: Setter methods (mutator methods)
The methods that modify the data-values of the field
27
True or False: Getter and setter methods must be public
True
28
By convention, the names of Getter and Setter methods use the prefix ____ and _____ followed by the _____
get, set, field-name (Example: getLength, setLength, getWidth, setWidth)
29
The objects in a program are initialized using a special method, called __________
constructor
30
True or False: The initialization of a method is done inside the definition of the constructor
True
31
Describe the properties of a constructor
Typically a public member method (can be private in a special scenario), must have the same name as the class, do not have a return type (not even void), can be overloaded
32
True or False: A constructor is automatically called when an object is constructed in the heap with the initialized values assigned to its members with the aid of a reference variable using the new operator
True
33
True or False: The String object is so widely used that this code can be simplified to the shorthand listed below: String name = new String("Bob Marley"); String name = "Bob Marley");
True
34
If name is a data-field in the following java statement, what does the name contain: String name;
null
35
If name is a reference-variable inside the main() method in the following java statement, what does name contain: String name;
Nothing, because it has not been initialized
36
True or False: A constructor is a special member method which is called every time an object is created and is designed to initialize member variables
True
37
True or False: There can be more than one constructor in a given class
True
38
If Circle is a class name in Java, what does the following statement inside a method do: Circle myCircle;
Nothing, because it has not been initialized
39
True or False: Public methods in a class can access private members of the objects of the same class
True
40
True or False: Private member methods of a class can access private members of other classes
False
41
What should the visibility standard of data members in a class?
They can have no visibility modifier (default) or they can be private or public or protected
42
If a class in Java does not contain any visibility modifier (such as private, public, protected) can that class be used by any other class from the other packages?
No
43
True or False: When passing a primitive-type parameter to a method, the parameter is copied to a new variable
True
44
True or False: When passing a primitive-type parameter to a method, changes to this parameter inside the called method affects the original value in the calling method
False
45
True or False: When passing a reference-variable, referring to an object, during a method-call, changes to this object inside the called method affects the original object in the calling method
True
46
The ________ operator can be used to assign one reference-variable of an object to another
Assignment (=)
47
True or False: When you design a class, you decide on the name of the class
True
48
True or False: When you use a class, you decide on the names of the instances (i.e., the reference-variable of an object) of that class
True
49
What is the default value of the boolean type local variable in Java?
Java assigns no default value to a local variable