Interview Questions

Q:

What is the purpose of declaring a variable as final?

Answer A final variable's value can't be changed. final variables should be initialized before using them.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2230
Q:

I do not want my class to be inherited by any other class. What should i do?

Answer You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2070
Q:

When will you define a method as static?

Answer When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3578
Q:

How is final different from finally and finalize()?

Answer final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed.

finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.

finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1812
Q:

Which king class properly represents the relationship "King has a best friend who is a Soldier"?

A) class King extends Soldier { } B) class King implements Soldier { }
C) class King { private BestFriend Soldier; } D) class King { private Soldier bestFriend; }
 
Answer & Explanation Answer: D) class King { private Soldier bestFriend; }

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Java

0 2386
Q:

How many of the following will follow JavaBean Listener naming rules?

addListener

addMouseListener

deleteMouseListener

removeMouseListener

registerMouseListener

 

A) 1 B) 2
C) 3 D) 4
 
Answer & Explanation Answer: B) 2

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Java

0 14248
Q:

Keeping the actoins and attributes together under a single unit is called 

A) Encapsulation B) Information Hiding
C) Polymorphism D) Inheritance
 
Answer & Explanation Answer: A) Encapsulation

Explanation:

Encapsulation is a process of binding the data objects together under a single unit.It is one ofthe elements of oops

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 2600
Q:

By whom will the unallocated memory that is no longer needed will be cleared in java?

A) Java Virtual Machine B) Garebage collector
C) Both A and B D) None
 
Answer & Explanation Answer: B) Garebage collector

Explanation:

The Java programming language provides a system-level thread to track memory allocation.

Garbage collection has the following characteristics:

• Checks for and frees memory no longer needed

• Is done automatically

• Can vary dramatically across JVM implementations

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 2479