Programming week 4-5

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/20

encourage image

There's no tags or description

Looks like no tags are added yet.

21 Terms

1
New cards

What is the goal of a constructor?

It is a compact way to initialize objects

2
New cards

Benefits of constructors

  1. Initialization is done before object can be used

  2. Initialization can be parametrized


3
New cards
<p>Explain all the arrows from top to bottom</p>

Explain all the arrows from top to bottom

knowt flashcard image
4
New cards

What is the difference between a constructor and a method

  1. a constructor has no return type, not even void

  2. a constructor has the same name as the class

  3. a constructor can only be called at construction

  4. a constructor can not be inherited


5
New cards

In one class there can be several constructors, as long as?

They have different parameter lists (as there can be methods with the same name and different parameters)

6
New cards

When a class has no constructor declarations

a constructor without parameters and an empty body is generated, called the default constructor

7
New cards

What does overloading mean

Using the same method name to do the same thing but with different parameter types

8
New cards

Explain Local Variables

Variables declared in a method are local to that method

9
New cards

Explain Instance variables

Variables declared outside the methods, i.e., at class level, are accessible for all methods

10
New cards

What are the 3 kinds of variables

  • Instance Var ( Scope is all methods in class ) - auto initialization

  • Parameters ( Scope is one method only ) - initialization by call

  • Local Var ( Scope is one method or less ) - initialization required


11
New cards

Scope of parameters

They are also local to their methods

12
New cards

What does the private keyword do?

Prevents access to instance variables

13
New cards

What is a reference?

It s a unique id each java object has

14
New cards

What is aliasing?

When you attribute to the same object to different names such as Object c = new Object() and b = c

15
New cards

What is the caveat for primitive types

Aliasing is not possbile

16
New cards

An object can only be assigned to a reference variable

Of its own type or one of its superclasses

17
New cards

When using inheritance what aspects of parent class are copied?

Existing instance variables and methods of parent class

18
New cards
<p>Explain what the red and blue arrows mean </p>

Explain what the red and blue arrows mean

Blue Arrow - Has a relation ( Tax Inspection has gardens )

Red Arrow - Is a relation

19
New cards

When talking about inheritance what is not copied

Constructors

20
New cards

What does overriding mean?

Changing methods in subclass that belong to the super-class

21
New cards

How do you access the old method after overriding?

super.oldMethod()