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

A

False

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
Q

Define: Getter methods (accessor methods)

A

The methods that retrieve/get the data-values of the field

26
Q

Define: Setter methods (mutator methods)

A

The methods that modify the data-values of the field

27
Q

True or False: Getter and setter methods must be public

A

True

28
Q

By convention, the names of Getter and Setter methods use the prefix ____ and _____ followed by the _____

A

get, set, field-name (Example: getLength, setLength, getWidth, setWidth)

29
Q

The objects in a program are initialized using a special method, called __________

A

constructor

30
Q

True or False: The initialization of a method is done inside the definition of the constructor

A

True

31
Q

Describe the properties of a constructor

A

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
Q

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

A

True

33
Q

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”);

A

True

34
Q

If name is a data-field in the following java statement, what does the name contain:

String name;

A

null

35
Q

If name is a reference-variable inside the main() method in the following java statement, what does name contain:

String name;

A

Nothing, because it has not been initialized

36
Q

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

A

True

37
Q

True or False: There can be more than one constructor in a given class

A

True

38
Q

If Circle is a class name in Java, what does the following statement inside a method do:

Circle myCircle;

A

Nothing, because it has not been initialized

39
Q

True or False: Public methods in a class can access private members of the objects of the same class

A

True

40
Q

True or False: Private member methods of a class can access private members of other classes

A

False

41
Q

What should the visibility standard of data members in a class?

A

They can have no visibility modifier (default) or they can be private or public or protected

42
Q

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?

A

No

43
Q

True or False: When passing a primitive-type parameter to a method, the parameter is copied to a new variable

A

True

44
Q

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

A

False

45
Q

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

A

True

46
Q

The ________ operator can be used to assign one reference-variable of an object to another

A

Assignment (=)

47
Q

True or False: When you design a class, you decide on the name of the class

A

True

48
Q

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

A

True

49
Q

What is the default value of the boolean type local variable in Java?

A

Java assigns no default value to a local variable