Search Header Logo

Inheritance

Authored by Dhilma Dhilma

Computers

12th Grade

Used 3+ times

Inheritance
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

7 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What type of inheritance is illustrated in the following Python code?

Multi-level inheritance

Multiple inheritance

Hierarchical inheritance

Single-level inheritance

Answer explanation

In multiple inheritance, two or more subclasses are derived from the superclass as shown in the above piece of code.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What will be the output of the following Python code?

A A

A B

B B

An exception is thrown

Answer explanation

obj1.two() invokes the method two() in class A which returns ‘A’ and obj2.two() invokes the method two() in class B which returns ‘B’.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is not a type of inheritance?

Double-level

Multi-level

Single-level

Multiple

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What will be the output of the following Python code?

Error, the syntax of the invoking method is wrong

The program runs fine but nothing is printed

1 0

1 2

Answer explanation

The invoking method has been properly implemented and hence x=1 and y=2.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What will be the output of the following Python code?

Error because class B inherits A but variable x isn’t inherited

0 0

0 1

Error, the syntax of the invoking method is wrong

Answer explanation

The invoking method has been properly invoked, variable x from the main class has been properly inherited and it can also be accessed.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Suppose B is a subclass of A, to invoke the init method in A from B, what is the line of code you should write?

A.__init__(self)

B.__init__(self)

A.__init__(B)

B.__init__(A)

Answer explanation

To invoke the init method in A from B, either of the following should be written: A.__init__(self) or super( ).__init__( ).

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What will be the output of the following Python code?

Invalid syntax for inheritance

Error because when object is created, argument must be passed

Nothing is printed

A disp( )

Answer explanation

Class B inherits class A hence the function disp () becomes part of class B’s definition. Hence disp() method is properly executed and the line is printed.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?