Inheritance and polymorphism

Quiz
•
Computers
•
University
•
Hard

Christian Dondrup
Used 105+ times
FREE Resource
6 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
The method of which class is called in the example below?
class A {
public void method() {...};
}
class B extends A {
public void method() {...};
}
class C extends B {
public void method() {...};
}
A obj = new C();
((B)obj).method();
The method in A
The method in B
The method in C
None of them; throws exception
2.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What type of error does this produce and why?
class Animal() {}
class Dog extends Animal {}
Dog dog = new Animal();
Compiler error; Because the dynamic type is the super class of the static type.
Compiler error; Because the static type is the super class of the dynamic type.
Runtime error; Because the dynamic type is the super class of the static type.
Runtime error; Because the static type is the super class of the dynamic type.
3.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What type of casting does the following piece of code use?
class Car {}
class SportsCar extends Car {}
Car car = new SportsCar();
Automatic downcasting
Automatic upcasting
Manual downcasting
Manual upcasting
4.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Assuming the class structure below, which of the following pieces of code correctly prints "Meow!"?
class Animal {}
class Cat extends Animal {
public void speak() {
System.out.println("Meow!");
}
}
...
Animal a = new Cat();
speak();
Animal.speak();
Cat.speak();
a.speak();
((Cat)a).speak();
5.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
What does type loss mean in the context of Java?
When manually casting using the static type in brackets before the name of a variable, it loses its dynamic type.
During downcasting the static type of the variable is replaced by the dynamic type of the obejct, therefore, the variable loses its type.
During upcasting the object assumes the static type of the variable and, therefore, loses its own static type.
When creating a subclass, the superclass loses its type and, therefore, the static type of the superclass becomes the dynamic type of the subclass.
6.
MULTIPLE SELECT QUESTION
1 min • 1 pt
Select all statements about ArrayLists that are true.
They are polymorphic
They are of fixed length
They are dynamic in length
They provide iterators
They can hold objects and simple data types such as int, double, boolean
Similar Resources on Wayground
10 questions
Java quiz 1

Quiz
•
University
10 questions
Latihan1

Quiz
•
University
10 questions
H466 - Arrays, Records, Tuples and Lists

Quiz
•
11th Grade - University
10 questions
[KUIPS]Python Matplotlib, Django, Raspi

Quiz
•
University
10 questions
Quiz on OOPs- Day 1 (30-01-2025)

Quiz
•
University
10 questions
Visual Basic Intro

Quiz
•
University
10 questions
Chapter 27

Quiz
•
University
10 questions
4. WB December RU

Quiz
•
8th Grade - University
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
21 questions
Spanish-Speaking Countries

Quiz
•
6th Grade - University
20 questions
Levels of Measurements

Quiz
•
11th Grade - University
7 questions
Common and Proper Nouns

Interactive video
•
4th Grade - University
12 questions
Los numeros en español.

Lesson
•
6th Grade - University
7 questions
PC: Unit 1 Quiz Review

Quiz
•
11th Grade - University
7 questions
Supporting the Main Idea –Informational

Interactive video
•
4th Grade - University
12 questions
Hurricane or Tornado

Quiz
•
3rd Grade - University
7 questions
Enzymes (Updated)

Interactive video
•
11th Grade - University