Day 10 - Inner class

Day 10 - Inner class

Assessment

Quiz

Professional Development

Professional Development

Hard

Created by

Nirmala Sherine

Used 8+ times

FREE Resource

Student preview

quiz-placeholder

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which is true about an anonymous inner class?


It can extend exactly one class and implement exactly one interface.

It can extend exactly one class and can implement multiple interfaces.

It can extend exactly one class or implement exactly one interface.


It can implement multiple interfaces regardless of whether it also extends a class.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which statement is true about a static nested class?

You must have a reference to an instance of the enclosing class in order to instantiate it.

It does not have access to nonstatic members of the enclosing class.

It's variables and methods must be static.


It must extend the enclosing class.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

class Foo 
{
    class Bar{ }
}
class Test 
{
    public static void main (String [] args) 
    {
        Foo f = new Foo();
        /* Line 10: Missing statement ? */
    }
}
which statement, inserted at line 10, creates an instance of Bar?

Foo.Bar b = new Foo.Bar();

Foo.Bar b = f.new Bar();

Bar b = new f.Bar();

Bar b = f.new Bar();

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

public class MyOuter 
{
    public static class MyInner 
    {
        public static void foo() { }
    }
}
which statement, if placed in a class other than MyOuter or MyInner, 
instantiates an instance of the nested class?

MyOuter.MyInner m = new MyOuter.MyInner();

MyOuter.MyInner m = new MyOuter.MyInner();

MyOuter m = new MyOuter();

MyOuter.MyInner mi = m.new MyOuter.MyInner();

MyOuter m = new MyOuter();

MyOuter.MyInner mi = m.new MyOuter.MyInner();

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which among the following best describes a nested class?

Class inside a function

Class inside a package

Class inside a structure

Class inside a class