Java Questions

Q:

Which is true?

A) "X extends Y" is correct if and only if X is a class and Y is an interface B) "X extends Y" is correct if and only if X is a class and Y is an interface
C) "X extends Y" is correct if X and Y are either both classes or both interfaces D) "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces
 
Answer & Explanation Answer: C) "X extends Y" is correct if X and Y are either both classes or both interfaces

Explanation:

A is incorrect because classes implement interfaces, they don't extend them. B is incorrect because interfaces only "inherit from" other interfaces. D is incorrect based on the preceding rules.

Report Error

View Answer Report Error Discuss

Filed Under: Java

2 5693
Q:

Which containers use a border Layout as their default layout ?

Answer

The window, Frame and Dialog classes use a border layout as their default layout.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

8 5691
Q:

I don't 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

2 5668
Q:

What is the access scope of a protected method?

Answer A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 5362
Q:

What’s the difference between Enumeration and Iterator interfaces ?

Answer

Enumeration is twice as fast as compared to an Iterator and uses very less memory. However, the Iterator is much safer compared to Enumeration, because other threads are not able to modify the collection object that is currently traversed by the iterator. Also, Iteratorsallow the caller to remove elements from the underlying collection, something which is not possible with Enumerations.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 5267
Q:

What is the importance of finally block in exception handling ?

Answer

A finally block will always be executed, whether or not an exception is actually thrown. Even in the case where the catch statement is missing and an exception is thrown, the finally block will still be executed. Last thing to mention is that the finally block is used to release resources like I/O buffers, database connections, etc.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

11 5197
Q:

How many constructors can a class have?

A) 1 B) 2
C) 4 D) None of the above
 
Answer & Explanation Answer: D) None of the above

Explanation:

A class can have any number of constructors. If a class have more than one constructor, we call it as the constructor is overloaded.

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Database Administration , IT Trainer

5 5185
Q:

Which containers use a FlowLayout as their default layout ?

Answer

The Panel and Applet classes use the FlowLayout as their default layout.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

3 5082