Basic Java Interview Question and Answers

77. Define Cloneable interface and clone() method?
 
  • The clone() method generates a duplicate copy of the object on which it is called. Only classes that implement the cloneable interface can be cloned.
  • The Cloneable interface defines no members. It is used to indicate that a class allows a bitwise copy of an object, i.e. a clone to be made.
  • CloneNotSupportedException is thrown, if clone() is called on a class that does not implement Cloneable.
 
Your Name Your Email-ID
Your Answer
78. How many ways can be argument be passed to subroutine and explain them?
  An argument can be passed in two ways. They are passing by value and passing by reference.
  • Passing by value: This method copies the value of an argument into the formal parameters of the subroutine.
  • Passing by reference: In this method, a reference to an argument is passed to the parameter.
 
Your Name Your Email-ID
Your Answer
79. What is a ResourceBundle?
  ResourceBundle is a Java class which is a more flexible solution for displaying language sensitive user messages. A message can contain several kinds of variables – dates, times, strings, numbers, currencies, and percentages. To format a message in a locale independent manner, you construct a pattern that you apply to a MessageFormat object, and store this pattern in a ResourceBundle. When a program needs a locale specific resource, such as String.
 
Your Name Your Email-ID
Your Answer
80. What do you know about Dynamic Initialization?
  Java allows variables to be initialized dynamically, using any expression valid at the time the variable is declared.
Class A
{
public static void main( string args[])
{
double a = 6.0, b= 8.0;
// here c is dynamically initialized
double c =Math .sqrt( a*a + b*b);
System.out.println( 'The result is ' + c);
}
}
Java does not support multiple inheritance, but it simulates this by the use of interfaces. Variables declared inside an interface declaration are implicitly final and static. One interface can inherit another by use of the keyword extends.
 
Your Name Your Email-ID
Your Answer