Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Core Java Interview Questions and Answers

Ques 6. How do you know if an explicit object casting is needed?

Ans. If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example:

Object a; Customer b; b = (Customer) a;
When you assign a subclass to a variable having a superclass type, the casting is performed automatically.

Is it helpful? Add Comment View Comments
Ques 7. What are the differences between the methods sleep() and wait()?
Ans.
  • The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. 
  • The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.
Is it helpful? Add Comment View Comments
Ques 8. Can you write a Java class that could be used both as an applet as well as an application?
Ans. Yes. Add a main() method to the applet.

import java.awt.*;
import java.applet.*;
import java.util.*;
public class AppApp extends Applet
{
public void init()
{
add(new TextArea("Welcome to withoutbook.com"));
String ar[]=new String[2];
ar[0]="Welcome to withoutbook.com";
main(ar);

public void main(String args[])
{
System.out.println(args[0]);
}
}
Is it helpful? Add Comment View Comments
Ques 9. What is the difference between constructors and other methods in core java?
Ans.
  • Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.
  • Constructor needs to have the same name as that of the class whereas functions need not be the same.
  • There is no return type given in a constructor signature (header). The value is this object itself so there is no need to indicate a return value.
  • There is no return statement in the body of the constructor.
  • The first line of a constructor must either be a call on another constructor in the same class (using this), or a call on the superclass constructor (using super). If the first line is neither of these, the compiler automatically inserts a call to the parameterless super class constructor.
Is it helpful? Add Comment View Comments
Ques 10. Can you call one constructor from another if a class has multiple constructors?
Ans.
Yes. Use this( ) syntax.
Sometimes a method will need to refer to the object that invoked it. To allow this, Java defines the this keyword. this can be used inside any method to refer to the current object. That is, this is always a reference to the object on which the method was invoked. You can use this anywhere a reference to an object of the current class type is permitted.
To better understand what this refers to, consider the following version of Box( ):
 
Box(double w, double h, double d) { 
this.width = w;
this.height = h;
this.depth = d;
}

The use of this is redundant, but perfectly correct. Inside Box( ), this will always refer to the invoking object.
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2016 WithoutBook