Unit 1 Flashcards

1
Q

Abstraction

A

Programming definition: “abstraction is the process of determining the set of features ( properties and methods) that a class will have”

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

Fundamental concepts of objects

A

1) an object is some computer code that occupies space in memory
2) the object has two main parts
its properties(data)
and it’s methods(named blocks of code that do something when they are called)

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

True or false: Everything in Java is an object.

A

False the eight primitive data types are not… they do not have any methods attached to them.

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

define class in java

A
a collection of code that contains the instructions for building an object of that class in memory
aka the blueprint for creating an object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When does an object get built in memory?

A

when the constructor method of the class file is called and executed

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

class vs object analogy

A

follow the recipe (the class) for chocolate chip cookies and the objects are the cookies that come out of the oven.

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

What are the three pillars of OOP?

A

1) Encapsulation
2) Inheritance
3) Polymorphism

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

Basic concept of encapsulation:

A

Access to the data and methods of a class can be controlled using the visibility modifiers public, protected and private

Basic idea of encapsulation is about being able to control access to an object’s properties and methods.

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

Inheritance

A
a sub-class (or child class) can inherit methods from its super class (or parent class) i.e it can make use of code written in the parent class without having that code written in its own class.
This means that we only need to write the method once in a parent or super class. (Yay! Less code to write!)
Sub-classes or child classes that are derived  or extended from the super class can inherit the method from the super class. Thus, they can call the method from the parent class.
In Java, every class we write inherits some methods and properties from the Object class, which Java provides for us. 
The Object class is often called “the mother of all classes”.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Polymorphism aka late binding or dynamic binding

A

you can have several methods with the same name defined in different classes of a class hierarchy. This is called method over-riding, as opposed to method overloading. These are different concepts

If an object invokes a method, the actual method that runs depends on the class of the object that made the method call. The JVM determines  this while the program is running.
The JVM will ask “OK, what is the class of the object that just called this method?” When it determines that it was an object of, say, class MyWidget, then the JVM will run the method that is defined in the MyWidget class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Classes

A

a class file is used to describe entities that have similar properties or attributes. similar to data modeling done in DB work. A customer class would describe the attributes and methods of customer objects.

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

In programing, think of a class as a ____ or ____ or ____ that defines the attributes and methods of objects of the same type. (T!)

A

description
blueprint
recipe

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

Object: an object is a particular ____ of a class. (T!)

A

instance

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

In java coding, we can think of an object as a collection of code that contains two things(T!):

A

1) some data in variables (aka properties, such as customer ID number)
2) some methods that can manipulate the data held in the variables.

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

An object ____ both the data and the methods of the object in the block of memory assigned to hold the object. (T!)

A

holds

Analogy: a single chocolate chip cookie is an object of the ChocolateChipCookie class.

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

The data held in an object is also sometimes referred to as the ____ of the object. (T!)

A

state

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

The state of an object is represented by the _______

A

values held in it’s data variables.

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

True or false: An objects state can change.

A

True if the variables values are modified.

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

object’s methods are referred to as its (T!)

A

behavior.

20
Q

define behavior

A

The behavior of an object is defined by whatever methods have been declared in the class. It is what the object can do. (T!)

21
Q

Basic class diagram is a:

A

a rectangle separated vertically into three sections

top section holds the name of the class
middle section holds the attributes (data variables) and their data types
bottom section holds the methods associated with the class.
22
Q

T/F: Given a class diagram, you should be able to write the code that will define that class. (T!)

A

True

23
Q

public:

A

accessible from any class anywhere

24
Q

private:

A

no access from outside the class at all

25
Q

protected

A

accessible from any class in the same package OR from any class that is a sub class of the class. This sub class could be located in another package and still have the access rights

26
Q

if you don’t specify any access modifer on an attribute or a method, Java will use the DEFAULT level of visibility which means:

A

only classes in the same package will have access to the data members and methods. any classes in other packages WILL NOT have access, even if they are sub–classes derived from the class

27
Q

To declare an object reference variable, format is :

A

ClassName objectName;

28
Q

to instantiate an object we must use the ___ key word

A
new
objectName = new ClassName();
29
Q

objectName = new ClassName();the brackets indicate that you are actually calling a method here. What method is getting invoked?

A

a constructor method is being called

30
Q

a constructor method definition differs in 2 ways from all other methods in Java (T!)

A

1) constructor method name is always exactly the same as the class name (so it begins with an UPPER CASE letter according to standard naming convention)
2) no return type is ever specified for a constructor method (not even void). What does get returned from a constructor method is an object of that class, but we do not specify this in the method header.

31
Q

a default constructor is not defined by the programmer. It

A

it is provided by Java automatically (T!)

32
Q

Circle myCircle = new Circle( );

A

the constructor method that Java provides for us if we do not specifically write one into our class.(T!)

33
Q

method overloading

A

creating your own methods so that we can set the property values of an object at instantiation time by calling a particular constructor

34
Q

As soon as you define a constructor method

A

the java default constructor will no longer be available to us.

35
Q

True or False: a no arg constructor is the same as the default constructor provided by java

A

false they are different

36
Q

why don’t we have to instantiate an object of the class to use the method?

A

a static method

37
Q

true or false: A class method is defined using the static modifier.

A
T!rue 
•Means that you don’t have to create an object of the class in order to call the method.
38
Q

what scope does a static variable have?

A
a class scope
meaning it is visible to every method in the class
39
Q

true or false: Every object created from that class will have that variable and its value as part of its data

A

true

40
Q

true or false: there is just one copy of a class variable in memory

A

true

41
Q

where do we declare the class scope?

A

between the opening and closing brace of the class

42
Q

true or false: If the class variable value is changed, all the objects in existence get the change, because they all refer to it !

A

true

43
Q

a public variable can be accessed by any other class or object

A

true

44
Q
which type of modifier?
the variables and methods of the class can only be accessed inside the class, or used by objects of the same class.
A

private

45
Q

what is good practice generally when deciding which modifier to use

A

private

46
Q

default and protected modifiers are the same

A

default is more restrictive than the protected level(same as protected aka restricts visibility to classes in the same package but classes RELATED BY INHERITANCE that are OUTSIDE of the package are cut off.