AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 1 - 5 of 5 questions

1
publicabstractclassAbstractTest 
{publicint getNum() 
    {
        return45;
    }
    publicabstractclassBar 
    {publicint getNum() 
        {
            return38;
        }
    }
    publicstaticvoid main (String [] args) 
    {
        AbstractTest t = new AbstractTest() 
        {
            publicint getNum() 
            {
                return22;
            }
        };
        AbstractTest.Bar f = t.new Bar() 
        {
            publicint getNum() 
            {
                return57;
            }
        };
        
        System.out.println(f.getNum() + " " + t.getNum());
    }
}

what wll be the output?
a

57 22

b

45 38

c

45 57

d

An exception occurs at runtime.

correct answer a
2
publicclassHorseTest 
{publicstaticvoid main (String [] args) 
    {
        classHorse 
        {public String name; /* Line 7 */public Horse(String s) 
            {
                name = s;
            }
        } /* class Horse ends */
        
        Object obj = new Horse("Zippo"); /* Line 13 */
        Horse h = (Horse) obj; /* Line 14 */
        System.out.println(h.name);
    }
} /* class HorseTest ends */

what will be the output?
a

An exception occurs at runtime at line 10

b

It prints "Zippo"

c

Compilation fails because of an error on line 7.

d

Compilation fails because of an error on line 13.

correct answer b
3
Which constructs an anonymous inner class instance?
a

Runnable r = new Runnable() { };

b

Runnable r = new Runnable(public void run() { });

c

Runnable r = new Runnable { public void run(){}};

d

System.out.println(new Runnable() {public void run() { }});

correct answer d
4

Which is true about a method-local inner class?

a

It must be marked final.

b

It must be marked abstract.

c

It must be marked public.

d

It must be marked static.

correct answer b
5
classBoo 
{
    Boo(String s) { }
    Boo() { }
}
classBarextendsBoo 
{
    Bar() { }
    Bar(String s) {super(s);}
    void zoo() 
    {
    // insert code here
    }
}
which one create an anonymous inner class from within class Bar?
a

Boo f = new Boo(24) { };

b

Boo f = new Bar() { };

c

Bar f = new Boo(String s) { };

d

Boo f = new Boo.Bar(String s) { };

correct answer b
Select a company to compare with

vs

Similar Companies