Easy Tutorial
For Competitive Exams

Which constructs an anonymous inner class instance?

Runnable r = new Runnable() { };
Runnable r = new Runnable(public void run() { });
Runnable r = new Runnable { public void run(){}};
System.out.println(new Runnable() {public void run() { }});
Explanation:

D is correct. It defines an anonymous inner class instance, which also means it creates an instance of that new anonymous class at the same time. The anonymous class is an implementer of the Runnable interface, so it must override the run() method of Runnable.

Option A is incorrect because it doesnt override the run() method, so it violates the rules of interface implementation.

Option B and C use incorrect syntax.

Additional Questions

Which method must be defined by a class implementing the java.lang.Runnable interface?

Answer

What will be the output of the following program on GCC?

include

int message();

int main() {

int x,y,z;

x=y=z=-1;

z=++x && ++y || ++z;

printf(" x=%d y=%d z=%d\n", x,y,z);

return 0;

}

Answer

If the sum of three consecutive even numbers is 44 more than the average of these numbers, then the largest of these numbers is?

Answer

Two trains 140 meters and 120 meters are running in the same direction with speeds 40 kmph and 60 kmph respectively. In what time will the faster train pass the slower one?

Answer

When a student weighing 45 kgs left a class, the average weight of the remaining 59 students increased by 200g. What is the average weight of the remaining 59 students?

Answer

A and B go cycling in the same direction with speeds of 6 km/hr. and 12 km/hr. A car from behind passes them in 9 and 10 seconds respectively. What is the speed of the car?

Answer

A sum of Rs. 4000 amounts to Rs. 4600 in 5 years at a certain rate of simple interest. What would be the amount, if the rate of interest is increased by 3 %?

Answer

For a candidate to clear an examination, he/she must score 55% marks. If he/she gets 120 and fails by 78 marks, the total marks for the examination is

Answer

A man on tour travels first 160 km at 64 km/hr. and the next 160 km at 80 km/hr. The average speed for the first 320 km of the tour is:

Answer

Shyam can do a job in 20 days, Ram in 30 days and Singhal in 60 days. If Shyam is helped by Ram and Singhal every 3rd day, how many days will it take for them to complete the job?

Answer
Share with Friends
Privacy Copyright Contact Us