Implementing Classes in Java Flashcards

1
Q

1) UML

ULM stands for: u___________ m____________ L__________________

A

Unified Modeling Language

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

2) Designing Classes

Useful to start by using a diagrammatic notation, normally UML.

In this notation, a class is represented by a box divided into three sections.

The first section provides the n______ of the class, the second section lists the a_______, and the third section lists the m_____________.

A

name
attributes
methods

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

3) In UML diagrams you will see a (+) or a (-) sign next to certain things.
e.g. -length : double
-height : double

        \+Oblong(double, double)
        \+getLength() : double

What does the (-) mean?
What does the (+) mean?

A

(-) means that the information is private - accessible only to methods within the same class
(+) means that the information will be public - accessible to methods of other classes

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

4) getters and setters

methods for r________ and w_________ the attributes conventionally begin with get- and set-respectively.

A

reading
writing

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

5) Constructor Methods

Do NOT have a r__________ or a v______ infront of them.

A

return
void

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

6)

Attributes of a class are accessible to all the m_______ of the class—unlike l_____ variables, which are accessible only to the methods in which they are declared.

A

methods
local

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

7) Public or private?

Unlike the a_________, we want our methods to be a___________ from outside so that they can be called by methods of other classes.

A

attributes
accessble

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

8) When we define a constructor in a class;

e.g. public Oblong(double lengthIn, double heightIn)
{
length = lengthIn;
height = heightIn;
}

The constructor is called a ‘u______-d_________ constrctor’.

A

user-defined constructor

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

9) Do we have to define a constructor method in our class?

A

No

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

10) What happens if we do not define a constructor method in our class?

A

one is automatically provided for us—this is referred to as the ‘default constructor.’

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

11) Does the default constructor take any parameters?

A

No.
I’m not even sure at this point if you would even see it on the screen.
I think it would just work if you created a new object.

e.g. Object my object = new Object( );

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

12) Can ‘constructor methods’ be overloaded like normal methods?

A

Yes, their names can also be reused. But again, with different parameters.

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

13) Developing a class

When developing a class we should always strive to restrict our methods to the e_______ f________ that define the class and to exclude anything that is concerned with the i______or o______ functions of a program.

If we do this, then our class can be used in any sort of application,

A

essential functions
input
output

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

14) ‘formal’ vs ‘actual’ parameters

The variables in the brackets of the method signature are the __________________________ of the method.

The _________________ are the values we send when we create a new object
e.g: myOblong = new Oblong(oblongLength, oblongHeight)

A

formal parameters
actual parameters

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

15) polymorphism

The technique of overloading method names is a very important feature of OO programming languages and is called p___________________ (having many forms).

A

polymorphism

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

16) The ‘static’ keyword

This type of word, along with words like ‘public’ and ‘private’ is called a ‘m________’.

A

modifier

17
Q

17) A modifier determines the particular way a class, attribute or method is a_________.

A

accessed

18
Q

18) What does the ‘static’ keyword do?

If we wanted one of our class attributes to hold the same value for every object that uses it, even if we change that value, we would use the keyword ‘static’

e.g. private static double interestRate:

The way this is achieved is by the program creating only one c____ of the attribute and making it accessible to all o_______.

A

copy
objects

19
Q

19) Attributes that have been declared as ‘Static’ are not object-specific anymore.
They are c_______-specific.

Because the static variable will be the same for all objects, and indeed the class. You can call it by the class name.
e.g.
public Employee (class name)

String emp1 = Tom;
String emp2 = Bob;
Static String ceo = David;

Tom.salary = 5000
Bob.id = 10
Emplyee.ceo = David \No need to specifiy Tom or Bob, as both will have the same ceo/value

e.g.

A
20
Q

20) What is the consequence of using ‘static’ attributes?

The consequence is that we do not need an o_____ to access static variables.
We just need the class name.

A

object

21
Q

21) We can also make methods ‘static’.
This means that we do not need an __________ to call the method.

e.g. The main method is static.

A

object

22
Q

22) Static methods do NOT need and o________ to be called, however, we do need objects for
i____________ methods.

A

object
instance methods