Java Programming Questions and Answers
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?
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?
Which constructs an anonymous inner class instance?
Which is true about a method-local inner class? |
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?