Unit_1 Flashcards

basic OO concepts

1
Q

the difference is between
a record and a class?

A

Records don’t support:
1. Encapsulation (restricting access to some fields,
information hiding)
2. Variables, behaviours at the class level (class variables,
class methods – “static” in Java)
3. Relationships to other classes (hierarchies,
inheritance)

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

What is an ADT?

A

Abstract Data Type (ADT):
◦ Structure the data in a useful fashion
◦ Keep its interface (how we interact with it) separated
completely from its implementation (the details of how
the operations and structuring is done)
◦ The point of the abstraction is to remove users from the
burden of understanding how things are dealt with
inside the data structure

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

What is a message?vv

A
  • An important idea of OOP is messaging: messages are
    sent to an object (by calling its methods), and then the
    object responds
  • Messages can have parameters:
    ◦ E.g.: create student named x with studentID y
  • Sender of the message (client)
    ◦ doesn’t know what actions will be done internally
    ◦ doesn’t know what methods the receiver will use to
    satisfy the requirements of the message
    ◦ doesn’t need to know/care/worry about this
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you want access to private members of the superclass inside the subclass, you can:

A

◦ Use accessor/mutator (get/set) methods
▪ Still a good reliable secure way to do it
◦ Declare the variables as protected instead of private in
the superclass
▪ This says “allow subclasses of this class to use this, too”
* This applies to methods, too,

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

GraphicalObject go = new Button();
What is the static type of go?
The dynamic type?

A

GraphicalObject go = new Button();

◦ The static type of go is GraphicalObject
◦ The (actual) dynamic type is Button
▪ what the variable is actually storing can be the same
class (static type) or any subclass → it must be looked
up at run time

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

How would you explain dynamic class binding in
one sentence?

A

Dynamic class binding refers to the process where the method or function call is resolved at runtime, based on the actual object type rather than the declared type.

class Animal {
void sound() {
System.out.println(“Animal sound”);
}
}

class Dog extends Animal {
@Override
void sound() {
System.out.println(“Bark”);
}
}

public class Main {
public static void main(String[] args) {
Animal myAnimal = new Dog(); // Dynamic binding
myAnimal.sound(); // Output: Bark
}
}
Here, myAnimal.sound() calls the sound() method from the Dog class at runtime, even though the reference type is Animal.

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

How would you explain dynamic method-
message mapping in one sentence?

A

Dynamic method-message mapping refers to the process where a method is selected and invoked based on the actual type of the object at runtime, rather than the type of the reference variable.

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

What do you think are some advantages of
object-oriented programming?

A
  • Software and Code Reusability
  • Understandability and Maintenance
  • Ease of Design
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly