Object Oriented Concepts Flashcards

1
Q

What is an object?

A

something that can be described by both data attributes (e.g., age, weight) and behavior
(e.g., eat, talk).

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

Explain this class diagram

A

The
top compartment contains the name of the thing being modeled…in our case a cat. The next
compartment contains a list of the attributes we are including in our model. And the bottom
compartment contains a list of relevant behaviors.

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

what is a class?

A

programming construct used to create objects. It defines the structure and behavior (data and code) shared by a set of objects.

It creates a new data type.

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

What is encapsulation?

A

a protective wrapper that controls access to the code and data through a well-defined interface

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

what does it mean if something is a “member” of a class?

A

the code and data in the class. Member variables and member methods

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

whats the difference between a public and private method?

A

public can be accessed outside of the class. Private methods can only be accessed by code that is a member f hte class.

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

What is inheritance

A

process by which one object acquires the properties of another object.

Important because it supports the concept of hierarchical classification (e.g. dog inherits mammal inherits animal)

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

What is polymorphism?

A

“one interface multiple methods”

one interface used for a general class of actions

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

What relationship between a class and an object?

A

object is instance of a class.

Class is template for an object

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

what does ‘new’ operator do

A

dynamically allocates (meaninning allocates at run time) memory for an object

Box mybox = new Box();
Box mybox; // declare reference to object
mybox = new Box(); //allocates a Box object

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

What is a constructor?

A

Defines what occurs when an object of a class is created.

class name followed by parentheses specifies the constructor for the class

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

Explain this situation:

Box b1 = new Box();
Box b2 = b1;

A

Both point to same object. Changing b2 will update for b1 too.

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

Whats difference between parameter and argument?

A

parameter is the variable defined by the method that receives the value.

argument is the value passed to a method when its invoked

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

How write the constructor method?

A

same name as the class with capital

Box () {
….
}

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

explain ‘this’

A

refers to the current object

this.width = w

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

what is garbage collection?

A

releasing of memory of objects no longer needed.

Java does it automatically

17
Q

What is method overloading

A

two methods with different parameter declarations. When called, Java executes the one with matching parameters

one way Java supports polymorphism.

18
Q

for overloading, will java do automatic type conversions (e.g. int to double) to execute a method?

A

yes

if no test(int) exists, it will elevate the argument to a double to execute test(double)

19
Q

Explain what it means what objects passed as parameters are call-by-reference?

A

When primitive types are passed, it creates a new local variable, and updates to that variable in that method do not affect within the invoking method.

In contract, objects pass the reference to that data. So updates in the current method will update the reference, and thus affect the invoking method.

20
Q

What does recursion mean with respect to a method?

A

Defining something in terms of itself. A method calling itself.

21
Q

what is a package?

A

a group of classes

22
Q

How is private and public used for access control to instance variables?

A

public means it can be accessed and edited outside of the class. object.variable = 10 sets the variable to 10.

private means that variable can only be set within that class through a defined method like setNum. object.setNum(10)

public int a;
private int b;

23
Q

what does static do?

A

methods and variable declarations that can be used before any instances of the class are created. They run first on their own.

24
Q

what does ‘final’ do?

A

prevents its contents from being modified.
Useful for parameters and local variables to prevent it from changing within the methods.
NOT useful for object parameters which are reference variables. Can still edit underlying.

final int FILE_NUM = 1;

common to use uppercase for constants

25
Q

What’s an inner class?

A

A class created within another block scope. Could be created within another class, method, or even loop.

It can access all the attributes from the outer class, but the outer does not have access to the inner.

26
Q

what is a command line argument?

A

info passed to program when you run it, stored in array args[]

27
Q

what are variable-length arguments and how to use them and why

A

if want to create a method that takes in zero or more arguments because you’ll just take in what you can get.

used with “…”

static void vaTest(int … v)

v is declared as an array with variable amount of data.

can call with parameters and variable length parameters but variable needs to be last

int test(int a, int b, double c, int … vals)

28
Q

What is containment?

A

using other objects as class members

29
Q

Class compilation

A

classes usually maintained as separate files (allows for parallel development)

classes compiled separately

30
Q

this

not sure really

A
31
Q

Can return an object from local method?

A

Yes Java will copy the reference before method variable destruction.

32
Q
A