
Unit 9 topic 2 quiz

Quiz
•
Computers
•
9th - 12th Grade
•
Medium
Michael Courtright
Used 2+ times
FREE Resource
12 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
public class ClassA
{ public void method1()
{ /* implementation of method1 / }
} public class ClassB extends ClassA {
public void method1(){
/ implementation of method1 / }
public void method2(){
/ implementation of method2 */ }
}
Which of the following is method1() in ClassB an example of?
information hiding
polymorphism
procedural abstraction
method overriding
method overloading
Answer explanation
Method overriding occurs whenever a method in a superclass is redefined in a subclass. Method overloading occurs when methods in the same class have the same name but different parameter types. In polymorphism, the correct overridden method is called for a particular subclass object during run time. Information hiding is the use of private to restrict access. Procedural abstraction is the use of helper methods.
2.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
class Cars {
void TransmissionType() {
System.out.println("Manual Transmission"); } }
class ElectricCar extends Cars
{ void TransmissionType()
{ System.out.println("AMT Transmission"); }
void showInfo() {
this.TransmissionType(); super.TransmissionType(); }
}
public class MethodOverridingCar {
public static void main(String[] args) {
ElectricCar ec = new ElectricCar(); ec.showInfo(); }
}
What will be the output of this code segment with method overriding and the keyword super?
Manual Transmission
AMT Transmission
AMT Transmission
Manual Transmission
AMT Transmission
AMT Transmission
no output
Manual Transmission
Manual Transmission
Answer explanation
The this keyword calls the subclass overridden method. The super keyword calls the method of the superclass. So, the output will display the subclass method and then the superclass method, as follows:
AMT Transmission
Manual Transmission
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Which of the following classes is the superclass of every class in Java?
Abstract class
ArrayList class
String class
Math class
Object class
Answer explanation
The Object class is the superclass of every class in Java. It is stored in the java.lang package and is the ultimate superclass of all Java classes except for the Object class itself.
Also, arrays extend the Object class. However, interfaces do not extend the Object class.
4.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
class Superclass{
/* instance variable /
int a = 10; / static variable */ static int b = 20; }
class Subclass extends Superclass{
void assignment(){
System.out.println(super.a);
System.out.println(super.b); }
public static void main(String[] args) {
Subclass mo = new Subclass(); super.a = 700; mo.assignment(); } }
What will be the output of this code segment?
700
20
no output
compilation error
10
20
run time error
Answer explanation
You cannot use the super keyword with a static variable; therefore, it will give a compilation error.
5.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
class Superclass{
/* instance variable /
int a = 36;
/ static variable */
static double x = 12.2; }
class Subclass extends Superclass{ void display() { super.a = 1;
System.out.println(a); super.x = 60.3;
System.out.println(x); }
public static void main(String[] args) {
Subclass m = new Subclass();
m.display(); } }
What will be the output of this code segment?
1
1
no output
compilation error
run time error
1
60.3
Answer explanation
The display() method is referring the class Parent instance variable (that is, a) super.a = 1; and then referring to the class Parent static variable (that is, x), assigning a new value super.x = 60.3;. The super keyword can access the static variables in the subclass. Therefore, it will display the following:
1
60.3
6.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
The keyword, this, is used to refer to the current class instance variables.
True
False
7.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
The keyword, this, can be passed as an argument in the method call representing the current object of the class.
True
False
Create a free account and access millions of resources
Similar Resources on Wayground
16 questions
Java Основи

Quiz
•
11th Grade - University
14 questions
Exploring Computer Science

Quiz
•
10th - 12th Grade
15 questions
Java Level 1 - C

Quiz
•
12th Grade
12 questions
Java G10 IT 1 - intro and conditionals

Quiz
•
10th Grade
14 questions
PBO KELAS 12

Quiz
•
12th Grade
15 questions
JAVA: Level-1

Quiz
•
5th - 12th Grade
10 questions
Computer Quiz(Java)(16-10-2020)

Quiz
•
9th Grade
9 questions
quis lat soal

Quiz
•
9th - 12th Grade
Popular Resources on Wayground
50 questions
Trivia 7/25

Quiz
•
12th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
11 questions
Negative Exponents

Quiz
•
7th - 8th Grade
12 questions
Exponent Expressions

Quiz
•
6th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
20 questions
One Step Equations All Operations

Quiz
•
6th - 7th Grade
18 questions
"A Quilt of a Country"

Quiz
•
9th Grade
Discover more resources for Computers
50 questions
Trivia 7/25

Quiz
•
12th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
18 questions
"A Quilt of a Country"

Quiz
•
9th Grade
6 questions
RL.10.1 Cite Evidence

Quiz
•
10th Grade
10 questions
Characteristics of Life

Quiz
•
9th - 10th Grade
14 questions
Algebra 1 SOL Review #1

Quiz
•
9th Grade