Java SE 11: Objects & Classes Flashcards

1
Q
A

Behavior

C D

Property

A B E

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

A Noun

B Adjective

C Verb

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

Given the following code, select the answers which best describe the type of variable alice.

Customer alice = new Customer( );

▢ Object reference

▢ Reserved world

▢ Class

▢ Primitive type

▢ Reference variable

A

√ Object reference

Reserved world

Class

Primitive type

√ Reference variable

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

Given the analogy of a remote to control a camera, what does this describe in Java?

  • How objects are accessed using object references
  • How multiple objects can represent Java objects
  • How objects consist of properties and operations
  • How objects are created or instantiated by their class type
A

How objects are accessed using object references

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

Select the necessary condition for a variable to reference an object.

You need a copy of the instantiated class

You need to use the remote keyword

You need a variable reference of the correct type

You need a universal variable

A

You need a variable reference of the correct type

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

What should be the output of the following code snippet?

Shirt myShirt = new Shirt();
Shirt yourShirt = new Shirt();
myShirt = yourShirt;
myShirt.colorCode = 'R';
yourShirt.colorCode = 'G';

System.out.println(myShirt.colorCode);

myShirt

G

R

yourShirt

A

G

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

Select the answer which describes how Java arrays are stored in memory.

Memory addresses on the heap

Primitive elements on the stack

Object stored on the heap

Object references on the stack

A

Object stored on the heap

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

What keyword is used to invoke a constructor?

new

object

class

public

construct

A

new

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

What return type is specified by a constructor method?

New

Class

Public

No type is specific

A

No type is specific

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

What is a value passed into a method called?

Parameter

Class

Argument

Object reference

A

Argument

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

Given a function that specifies a return type of void, what will it return?

A class

A void reference

Nothing

An object reference

A

Nothing

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

Select the elements that make up a method signature.

▢ Number parameters

▢ Modifier

▢ Parameter types

▢ Method name

▢ Return type

▢ Order of parameters

A

√ Number parameters

▢ Modifier

√ Parameter types

√ Method name

▢ Return type

√ Order of parameters

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

Given the following code, what is the scope of the price field?

public class Shirt {

public String description;

public char colorCode;

public double price;

public void setPrice(double thePrice) {

price = thePrice;

}

public double getPrice() {

return price;

}

The global application

The Shirt class

The setPrice method

The getPrice method

A

The Shirt class

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

Devide section by Class name, Fields and Methods.

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

What’s the difference between declaring an object and instatiating an object

A

No value is assigned when an object is just declared.

Initialization is the assignment of a value to a variable at the time of declaration.

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

what is the . operator for?

A

The period . operator is used to access the fields and methods of an object.

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

In java you access objects using ________

A

references

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

Objects are created or ________ by their class type.

A

instantiated

20
Q

Any object consist of properties and operations, which we call _____ and ______ in Java

A

Any object consist of properties and operations, which we call fields and methods in Java

21
Q

References point to a particular object in _____

A

memory

22
Q

In this snippet of code we have three variables:

int counter = 10

Shirt myShirt = new Shirt

Shirt yourShirt = new Shirt.

How many objects end up in memory?

A

Two objects in memory

23
Q

A primitive type int is stored as an object.

True or False

A

False

24
Q

A primitive type int is stored as a _______.

A

variable

25
Q

Variable types and references are store in the _____

A

stack

26
Q

Object types are store in the _____

A

Heap

27
Q

The stack holds local variables, either ______ or _______ ____

A

The stack holds local variables, either primitives or reference types

28
Q

What happens if you assign an existing reference to another reference?

A

The existing reference will drop it’s current object and re-assigned to the same object of the new reference.

29
Q

An array is actually an _____ type and is handled implicitly through an internal class in Java called _____.

A

An array is actually an object type and is handled implicitly through an internal class in Java called Array.

30
Q

Like other object types with string being an exception, an array must be instantiated using the ___ keyword

A

Like other object types with string being an exception, an array must be instantiated using the new keyword

int[] ages = new int [4];

exception: int[] ages = { 8, 7, 5, 3 };

31
Q

Arrays are _____ in memory that are referred to by an object _____ _____

A

Arrays are objects in memory that are referred to by an object reference variable

32
Q

The public keyword is a _____

A

The public keyword is a _____

33
Q

____ is a keyword that indicates that the method does not return a value

A

void is a keyword that indicates that the method does not return a value

34
Q

The _____/_____ method is the main method or a method that calls another method to do work.

A

The caller /calling method is the main method or a method that calls another method to do work.

35
Q

A __________ ______ is a special method that is invoked when you create an object instance

A

A Contrustor Method is a special method that is invoked when you create an object instance

36
Q

A constructor method is called by using the ___ keyword.

A

new

Shirt myShirt = new Shirt ( )

37
Q

The _____ _______ is the unique combination of a method’s name, the number, types, and order of its parameters.

A

The Method Signature is the unique combination of a method’s name, the number, types, and order of its parameters.

public double add (double x, double y)

public int add (int x, int y)

38
Q

The method signature does not include the _____ ____

A

return type

39
Q

So the _____ of a variable determines where you can access the variable and for how long you can count on its value to persist.

A

So the scope of a variable determines where you can access the variable and for how long you can count on its value to persist.

40
Q

A variable is usually called a _____ when it’s in a class

A

field

41
Q

Instance variables or fields are stored in the long term memory ____

A

Instance variables or fields are stored in the long term memory heap

42
Q

An instance variable is accessible from any code within this ____

A

class

43
Q

Local variables are stored in the ____

A

stack

44
Q

A local variable is ______ from ______ when the method ends

A

A local variable is deleted from memory when the method ends

45
Q

A ____ _____ in Java is a variable that’s declared within the body of a method.

A

local variable

46
Q

______ _________ is a feature that allows a class to have more than one method having the same name, if their ______ lists are different

A

Method Overloading is a feature that allows a class to have more than one method having the same name, if their argument lists are different

add(int, int)

add(int, int, int)

add(int, float)

add(float, int)

47
Q

A ____, in the context of Java, are templates that are used to create objects, and to define object data types and methods. Core properties include the data types and methods that may be used by the object

A

class