Interview Questions

Q:

How will you define an abstract class?

Answer

An abstract class is defined with the keyword abstract Eg:
public abstract class MyClass { }

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1312
Q:

What is the difference between array and ArrayList ?

Answer

Array is collection of same data type. Array size is fixed, It cannot be expanded.


 


But ArrayList is a growable collection of objects.ArrayList is a part of Collections Framework and can work with only objects.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1417
Q:

What is diamond problem?

Answer

The diamond problem is an ambiguity that can occur when a class multiply inherits from two classes that both descend from a common super class

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1712
Q:

What is the security mechanism used in java?

Answer

Java uses sand box security model.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1426
Q:

What is encapsulation?

Answer

Encapsulation describes the ability of an object to hide its data and methods from the rest of the world 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1699
Q:

What is inheritance?

Answer

Inheritance is the ability to create new classes based on existing classes. It is useful to reuse existing code.

Report Error

View answer Workspace Report Error Discuss

0 1982
Q:

Can we compile a java program without main?

Answer

Yes, we can. In order to compile a java program, we don't require any main method. But to execute a java program we must have a main in it (unless it is an applet or servlet). Because main is the starting point of a java program.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1609
Q:

What are the restrictions when overriding a method ?

Answer

Overridden methods must have the same name, argument list, and return type (i.e., they must have the exact signature of the method we are going to override, including return type.)


The overriding method cannot be less visible than the method it overrides( i.e., a public method cannot be override to private).


The overriding method may not throw any exceptions that may not be thrown by the overridden method

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2338