
Unit 9 topic 2 quiz
Quiz
•
Computers
•
9th - 12th Grade
•
Practice Problem
•
Medium
Michael Courtright
Used 2+ times
FREE Resource
Enhance your content in a minute
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
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
12 questions
HTML & Java
Quiz
•
9th Grade
10 questions
DTJSQuiz
Quiz
•
11th Grade
17 questions
Music, Politics, Poetry, Tech 2021
Quiz
•
3rd Grade - University
10 questions
Penilaian Harian-1, Pemrograman Berorientasi Objek (PBO)
Quiz
•
12th Grade
15 questions
Q1 W1 M1 PRE-TEST
Quiz
•
10th Grade
15 questions
Bluetooth and Wi-Fi Quiz
Quiz
•
7th Grade - University
15 questions
Types of Network
Quiz
•
10th Grade
10 questions
Cutting - Edge Technology
Quiz
•
7th - 10th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
