Class, Objects, Methods & Properties Flashcards

1
Q

What is a Class?

A

A blueprint that we create to describe a component of our app.

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

How do you create a Class? 2 Steps.

A
  1. ) Type “Class” and give it a name.

2. ) Open { } and type: init ( ) { }

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

What is init?

A

It’s an initializer. It’s a special type of method.

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

What is init used for?

A

All Classes must have an initializer. Any code you put in-between the curly brackets within init, gets executed when a new object of a certain class is created.

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

What is an object?

A

Objects are always created from the Class.

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

How do you create an object?

A

Class name followed by ( )

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

What is the easiest way to reference an object? Please give an example.

A

Turn the object into a variable.

Example: 
var a = Person( )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the print line statement provide? Give it’s form.

A

Print Line statements are made to call out a newly created object.

Form: println (“This is what will print”)

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

What is a method and what is it used for?

A

A named set of instructions that will be executed when called. They are created using the “func” keyword.
Expression:

func GiveMethodName ( ) { }

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

What is written in the curly brackets of the method expression?

A

Inside the curly braces you write the code to execute when the method is called.

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

The code inside the curly braces of the method expression would yield:

A

Println(“CalledMethod”) This line of code will only be executed if the func method is called.

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

Once a method is created, how would you call it? Give an example.

A

Object.MethodName( ) The var is the object you created from the Class.

Example: Since I created the var to easily reference the object, it would be called by:

a.Walk( )

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

Where are Properties created within a class? First, Second or Last?

A

Properties are always

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

How do you call a method from the initializer?

A

Go up to inti ( ) { } and type:

self.MethodName( ) - self means call a method you own yourself.

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

Give the expression for a Property. And give an example.

A
  • var PropertyName: The data the property is going to store/track = an initial value

var Name:String = “Initial Name”

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

What can be said about String?

A

**String is just a piece of text.

17
Q

What are the differences between the var declaration and a property declaration?

A
  • Properties are used within the Class created

- Variables are used within the Method created.

18
Q

What expression would you use to call a property?

A

In order to call a property, it follows the same format as the method call.

object.propertyName

19
Q

What is a SubClass and why is it helpful?

A

A subclass inherits the properties and methods of another class. It allows you not to duplicate code.

20
Q

How would on create a subclass? Give one benefit of this subclass.

A

class Subclass Name : ParentClassName { }

This allows you to build new functionality within the subclass.

21
Q

What is another name for the parent class?

A

Super Class.

22
Q

How would you override a function of the parent class?

A

override func ParentClass Method( ) { }

23
Q

How do you call both functions of the Parent and Sub Class?

A

super.nameofthefunction within the subclass.