Unit 9 topic 2 quiz

Unit 9 topic 2 quiz

9th - 12th Grade

12 Qs

quiz-placeholder

Similar activities

W8-11

W8-11

10th - 11th Grade

10 Qs

Java Exception Handling

Java Exception Handling

11th Grade

17 Qs

Pertanyaan pemantik PBO Kelas XII - 1

Pertanyaan pemantik PBO Kelas XII - 1

12th Grade

10 Qs

Java

Java

11th Grade - University

12 Qs

Arrays

Arrays

10th - 12th Grade

14 Qs

week 1 basic java coding language

week 1 basic java coding language

9th - 12th Grade

12 Qs

Java Level 1 - B

Java Level 1 - B

12th Grade

15 Qs

APCSU1D5 Compound Assignments

APCSU1D5 Compound Assignments

12th Grade

10 Qs

Unit 9 topic 2 quiz

Unit 9 topic 2 quiz

Assessment

Quiz

Computers

9th - 12th Grade

Medium

Created by

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

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?