Unit4 Flashcards

1
Q
  1. What is the primary purpose of inheritance in object-oriented programming?
    • a) To allow new objects to be made from existing ones.
    • b) To allow classes to derive from multiple base classes.
    • c) To provide a way for classes to obtain all the properties and behaviors of another class.
    • d) To restrict access to methods in the superclass.
A

Correct Answer: c) To provide a way for classes to obtain all the properties and behaviors of another class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Which statement is true about polymorphism?
    • a) It allows methods to perform differently in different instances.
    • b) It restricts methods from being overridden.
    • c) It only applies to static methods.
    • d) It prevents classes from inheriting features from their parent classes.
A

Correct Answer: a) It allows methods to perform differently in different instances.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What does the extends keyword signify in a Java class definition?
    • a) The class is being enhanced with additional methods.
    • b) The class is providing new implementations for base class methods.
    • c) The class is inheriting from a superclass.
    • d) The class cannot be instantiated.
A

Correct Answer: c) The class is inheriting from a superclass.

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

*Consider the following classes:
javaCopy code
public class Fruit {
public void flavor() { System.out.println(“Fruit flavor”); }
}
public class Orange extends Fruit {
public void flavor() { System.out.println(“Orange flavor”); }
}

What is this an example of?**

  • a) Overloading
  • b) Overriding
  • c) Dynamic Binding
  • d) Static Binding
A

Correct Answer: b) Overriding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. Which of the following is a correct example of polymorphism?
    • a) Fruit myFruit = new Orange();
    • b) Orange myOrange = new Fruit();
    • c) Fruit myFruit = new Fruit();
    • d) Orange myOrange = new Orange();
A

Correct Answer: a) Fruit myFruit = new Orange();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What is early binding?
    • a) The type of binding where method calls are resolved at runtime.
    • b) The type of binding where method calls are resolved as soon as the class is loaded.
    • c) The type of binding where method calls are resolved at compile time.
    • d) The type of binding that occurs only in interpreted languages.
A

Correct Answer: c) The type of binding where method calls are resolved at compile time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. What is the result of the super keyword in an overridden method?
    • a) It calls the overridden method in the superclass.
    • b) It prevents the method from being overridden.
    • c) It deletes the method from the superclass.
    • d) It renames the method in the superclass.
A

Correct Answer: a) It calls the overridden method in the superclass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. How does Java implement multiple inheritances?
    • a) Through direct extension of multiple classes.
    • b) Through interfaces.
    • c) Java does not support multiple inheritances.
    • d) Through virtual classes.
A

Correct Answer: b) Through interfaces. (Note: Java does not support multiple inheritances through classes but allows a class to implement multiple interfaces.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Which of these is a use of downcasting?
    • a) To access methods that the reference type doesn’t have.
    • b) To restrict the functionality of an object.
    • c) To convert primitive types into objects.
    • d) To prevent exceptions in method calls.
A

Correct Answer: a) To access methods that the reference type doesn’t have.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. What is displayed when a subclass object calls super.methodName() and this method is overridden in the subclass?
    • a) The method in the superclass is called.
    • b) The method in the subclass is called.
    • c) A runtime error occurs.
    • d) A compile-time error occurs.
A

Correct Answer: a) The method in the superclass is called.

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