Unit_1 Flashcards
basic OO concepts
the difference is between
a record and a class?
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)
What is an ADT?
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
What is a message?vv
- 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
If you want access to private members of the superclass inside the subclass, you can:
◦ 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,
GraphicalObject go = new Button();
What is the static type of go?
The dynamic type?
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 would you explain dynamic class binding in
one sentence?
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 would you explain dynamic method-
message mapping in one sentence?
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.
What do you think are some advantages of
object-oriented programming?
- Software and Code Reusability
- Understandability and Maintenance
- Ease of Design