Module 01-09 Introduction to Classes Flashcards

1
Q

What are classes?

A

Classes serve as blueprints that indicate what variables and methods an object has.

Many individual objects with different variables and methods can be made from the same class.

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

Variables and properties represent an object’s…

A

State

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

Methods indicate an object’s

A

Behaviors

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

How would you declare an instance of class Clock called clock?

A

Clock clock = new Clock();

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

Private and Public are called…

A

Access modifiers.

They control visibility to methods and properties to the rest of your program.

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

A derived property…

A

Lets you generate a value by relying on the other properties within the class.

A derived property is a getter that, instead of returning a member variable, returns a calculation taken from member variables. If we have firstName and lastName, we don’t need to also store fullName, we can derive it from what we already have.

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

Methods are for when you need and object to…

A

do something! (perform a behavior)

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

What does Encapsulation do?

A

Encapsulation lets you restrict access to the internal mechanism of how the class works by hiding or protecting its variables.

It’s the first pillar of object-oriented programming.

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

What do methods with “void” method signatures return?

A

Nothing!

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

What is a constructor?

A

A constructor is a special method that runs every time a new object is instantiated. It allows for the object to be initialized with a starting state.

It doesn’t return anything.
It must have the same name as the Class.
It can have arguments that set the value of member variables, like a Setter.
It can be Overloaded to provide multiple ways to instantiate the object.
If no constructor is present, then Java provides a default constructor, which has no arguments.

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

Three Rules of an Overloaded Method

A
  1. Overloaded methods must have the same name.
  2. Overloaded methods must have the same return type (does not apply to constructors).
  3. Overloaded methods must differ in the number of parameters and/or parameter types.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Inheritance?

A

Inheritance is the practice of creating a hierarchy for classes in which descendants obtain the attributes and behaviors from other classes.

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

What is Polymorphism?

A

Polymorphism is the ability for our code to take on different forms. In other words, we have the ability to treat classes generically and get specific results.

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

All Reference Types are defined by a…

A

Class

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

All Classes are defined by a…

A

Data Type

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

True or False: Class name must match the file name

A

True.

Inside of Car.java file you have the class Car

17
Q

Classes should be named

A

with singular nouns or noun phrases in Pascal case (OneTwoThree)

18
Q

What do Member Variables (aka Instance Variables) do?

A

Member variables create object state. They should always be private.

Getters and Setters should be the only way to access member variables from outside the class.

19
Q

Getter and Setter methods should always begin with…

A

the “get” or “set” prefix, except for Getter methods that return a boolean, which should begin with the prefix “is”.

20
Q

The this keyword refers to…

A

the member variable specific to the instance of an object where the code is run.

21
Q

How do you declare a public method that takes a String and returns the String reversed?

A

public String reverser(String x)