Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Congrats !!! You Have Successfully Completed The Session:) ..

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

T1 - Topic 5...

/ Inheritance / Explore
×
 CONGRATS!!!
Congrats !!! You have successfully completed the session :) ... TOTAL SCORE: 80.0%

INHERITANCE / EXPLORE Answered Questions : 12 / 15 Your Score : 80.0% 

ANSWERED
PROBLEM POINTS
CORRECTLY
Check

When do we use Abstract class? 1.0 Correct Answer
Answer 

When do we use Abstract class?

1) To prevent developers from further extending the class.

2) When it doesn't make sense to have objects of that class.

3) When default implementations of some methods are not desirable.

4) To force developers to extend the class not to use its capabilities.


What is the output of this program?   class A {
    final int a = 15;
}
class B Check
1.0 Correct Answer
extends A {
  ... Answer 
ANSWERED
PROBLEM POINTS
CORRECTLY

What is the output of this program?

 
class A {
    final int a = 15;

class B extends A {

    final int a = 20;

public class C extends B {

    final int a = 30;

    public static void main(String args[]) {

        B b = new C();

        System.out.print(b.a);

    }
}

1) 15

2) 20

3) 30

4) compilation error


What is the output of the below program?   class Main {
    public static void Check
1.0 Correct Answer
print(Integer i... Answer 

What is the output of the below program?

 
class Main {

    public static void print(Integer i) {

        System.out.println(2*i);

    }
    public static void print(String s) {

        System.out.println(s);

    }
    public static void main(String[] args) {

        print("5");

    }
}

1) 5

2) 10

3) compilation error

4) null
ANSWERED
PROBLEM POINTS
CORRECTLY

What should be filled in the 13th line to make the code compilable?   1.class Check
0.0 Wrong Answer
A {
2.    A(Integ... Answer 

What should be filled in the 13th line to make the code compilable?

 
1.class A {

2.    A(Integer a){}

3.
4.    A(){}

5.}
6.
7.class B extends A {

8.    B(){}

9.    B(Integer a) {

10.      super(a);

11.   }
12.   void test(){

13.      // insert code here

14.   }
15. }

1) A a = new B(a);

2) A a = new B("3");

3) A a = new B(Integer a);

4) A a = new B(5);


What is the output of this program? abstract class TestAbstract {
    String Check
1.0 Correct Answer
name;
    String ... Answer 
ANSWERED
PROBLEM POINTS
CORRECTLY

What is the output of this program?


abstract class TestAbstract {

    String name;

    String myName(){

        name = "Alexander";

        return name;

    }
    abstract void display();

public class Test extends TestAbstract {

    void display(){

        String n = myName();

        System.out.print("My name is "+ n);

    }
    public static void main(String args[]) {

        Test t = new Test();

        t.display();

    }
}

1) Program will compile and execute successfully and prints the output.

2) Compilation error as class can not be declared as abstract.

3) Program compiles but leads to runtime exception.

4) Compilation error occurs as the abstract class TestAbstract contains a non-abstract method.

Check

A variable is declared as ______ to restrict the sub class from inheriting it. 1.0 Correct Answer
Answer 

A variable is declared as ______ to restrict the sub class from inheriting it.

1) protected

2) private

3) public

4) static


What is the output of this program?   class A {
    final int a = 15;
}
class B Check
1.0 Correct Answer
extends A {
  ... Answer 
ANSWERED
PROBLEM POINTS
CORRECTLY

What is the output of this program?

 
class A {
    final int a = 15;

class B extends A {

    final int a = 20;

public class C extends B {

    final int a = 30;

    public static void main(String args[]) {

        C c = new B();

        System.out.print(c.a);

    }
}

1) 15

2) 20

3) 30

4) Compilation error

Check

In Java, Multiple inheritance are implemented by_________. 1.0 Correct Answer
Answer 

In Java, Multiple inheritance are implemented by_________.

1) Interfaces

2) Multithreading

3) Protected methods

4) Private methods


Consider the following situation and answer the question There are two Check
0.0 Wrong Answer
classes, Class A and Class... Answer 
ANSWERED
PROBLEM POINTS
CORRECTLY

Consider the following situation and answer the question

There are two classes, Class A and Class B.

Class B extends A.

Both have a method with same name but with different signatures (arguments).

What does it say about the above mentioned method?

The method is said to be ___________.

1) overridden

2) overloaded

3) overridden and overloaded

4) static

10 
What happens when the program is executed?   class A {
    public void Check
1.0 Correct Answer
method() {
        Syste... Answer 

What happens when the program is executed?

 
class A {
    public void method() {

        System.out.println("Hi i am A");

    }
}
public class B extends A {

    protected void method(){

        System.out.println("Hi i am B");

    }
    public static void main(String args[]){

        B b = new B();

        b.method();

    }
}

1) Compiles successfully and prints "Hi i am A"

2) Compiles successfully and prints "Hi i am B"

3) Compile time error

4) Run Time error

11 
What is the output of this program?   class A {
    final int method() {
        Check
1.0 Correct Answer
return 100;
  ... Answer 
ANSWERED
PROBLEM POINTS
CORRECTLY

What is the output of this program?

 
class A {
    final int method() {

        return 100;

    }
}
public class B extends A {

    private int method() {

        return 50;

    }
    public static void main(String[] args) {

        A a = new B();

        System.out.println(a.method());

    }
}

1) 100

2) 50

3) compilation error

4) runtime error

Check
12 
Which of the following cannot be overriden?   1.0 Correct Answer
Answer 

Which of the following cannot be overriden?

1) class methods

2) protected methods

3) default method

4) public methods

5) static methods

13 
What is the output of this program?   class Test {
    public static void Check
1.0 Correct Answer
print(Integer i) {
 ... Answer 
ANSWERED
PROBLEM POINTS
CORRECTLY

What is the output of this program?

class Test {

    public static void print(Integer i) {

        System.out.println(2*i);

    }
    public void print(String s) {

        System.out.println(s);

    }
    public static void main(String args) {

        print("5");

    }
}

1) 5

2) 10

3) compilation error

4) None of the listed options

Check
14 
In Java, which of the following keywords prevent method overriding?   1.0 Correct Answer
Answer 

In Java, which of the following keywords prevent method overriding?

1) static

2) constant

3) protected

4) final

Check
15 
All classes in Java inherit ________ class. 0.0 Wrong Answer
Answer 
ANSWERED
PROBLEM POINTS
CORRECTLY

All classes in Java inherit ________ class.

1) java.lang.class

2) java.class.inherited

3) java.class.object

4) java.lang.Object

Go to course
×
Test Case Details

×
Calendar
No Content
Close
×
Notification
Close
×
Enrolment Schedule

Close
X
×
×
Message

Close

Are you sure ?

CANCEL
OK

You might also like