PPQ Flashcards

1
Q

What does “private int a = 5” mean?

A

It means that a which is a type primitive int is only accessible within this class called…

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

What does the method signature “setA(int b) mean?

A

setA means it is a setter methods which allows other classes to set the value of a because it is a private variable.
The int b is the value that will be passed to the setA method. It will set the value of a to be that value b.

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

What is the toString() an example of?

A

toString() in this class is an example of overriding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
What is being created here.
ExamQ2 ee = new ExamQ2(a)
A

An object of type ExamQ2 with a reference ee.

It is being passed a.

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

Discuss static methods and variables.

A

We can have static instance variables and static methods.

Both are associated with the class itself, not the object.

Therefore, statics can be accessed without instantiating the object.

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

Discuss a static variable

A
Like a global variable, but on a class by class basis. It is stored in the class.
Static variables occur as a single copy in the class ( instance variables occur as multiple copies - one in each instance (object).
eg., system.out is a static variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Discuss static methods.

A
Like a "global function" but on a class by class basis.
There is no receiver because the static method is associated with the class, there is no object is associated with it, and therefore no receiver. You can think of it as the class being the receiver.
Eg., System.arrayCopy()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain what makes GUI programs different to programs in which interaction is driven by a command line interface.

A
  • User controls GUIs
  • User can close the window and click buttons etc.
  • Easy to use
  • Consumes more memory & is slower
  • User can’t really control command line actions
  • Need to follow specific instructions on what happens & write it themselves.
  • Difficult to use
  • Faster & uses less memory

Eg., compare navigating a directory vs clicking on something

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

What is an interface?

A
  • Interfaces are a collection of abstract methods with no implementations, constructors and don’t return anything. Can also define constant variables.
  • Useful when you want to implement certain functionality, but there are no shared attributes.
  • Any class can implement an interface as long as they include the methods from the interface.
  • Any objects from a class that implements an interface can be stored in a reference of the type of the interface
  • Java classes have single inheritance, interfaces have multiple inheritance

ie., shape interface, rectangle implements interface
Shape rectangle = new Rectangle (2,4)

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

What are the advantages of interfaces?

A
  • A class can implement more than one interface (can only have one superclass)
  • An interface can extends another interface or interfaces (more than one interface) .
  • All methods are public & abstract
  • Can make a reference of the interface that refers to the object of that class that is implementing it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the advantages of interfaces to the programmer?

A
  1. Lightweight & simple mechanism
    Programmers are able to respond to a common set of messages, without making the code too complex. This is a lot lighter than a sub class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the disadvatnages of interfaces to the programmer?

A
  1. Only gives prototypes, not implementation code which means programmers need to create the code from scratch.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between inheritance and interfaces?

A
  • Java classes have single inheritance, interfaces have multiple inheritance.
  • Class inheritance usually have shared attributes, but interfaces can be anything.
  • Interfaces have only public methods and constant variables, unlike abstract classes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly