Interview Question and Answers Part 5
Interview Question and Answers Part 5
by Administrator |
Which method is used to determine the class of an object?
getClass( ) method can be used to find out what class belongs to. This class is defined in the object class and is available to all objects.
All the classes in java.lang package are automatically imported when a program is compiled.
How can a class be imported to a program?
To import a class, the import keyword should be used as shown:
How can a class be imported from a package to a program?
import java.packagename.classname (or) import java.packagename.*;
What is a constructor?
A constructor is a special kind of method that determines how an object is initialized when created.
Can Constructors be overloaded like regular methods?
What is casting?
Casting is used to convert the value of one datatype to another.
Can Boolean values be cast into primitive types?
Which casting should be used to convert a larger value into a smaller one?
Which of the following features are common to both Java & C++?
The class declaration
The access modifiers
The encapsulation of data & methods within objects
The use of pointers
Which of the following statements accurately describe the use of access modifiers within a class definition?
They can be applied to both data & methods
They must precede a class's data variables or methods
They can follow a class's data variables or methods
They can appear in any order
They must be applied to data variables first and then to methods
Which of the following statements can be used to describe a public method?
It is accessible to all other classes in the hierarchy
It is accessible only to subclasses of its parent class
It represents the public interface of its class
The only way to gain access to this method is by calling one of the public class methods
Which of the following types of class members can be part of the internal part of a class?
Public instance variables
Private instance variables
Which of the following statements correctly describes the relationship between an object and the instance variable it stores?
Each new object has its own distinctive set of instance variables
Each object has a copy of the instance variables of its class
the instance variable of each object is separate from the variables of other objects
The instance variables of each object are stored together with the variables of other objects
What are the functions of the dot(.) operator?
It enables you to access instance variables of any objects within a class
It enables you to store values in instance variables of an object
It is used to call object methods
It is to create a new object
Which of the following can be referenced by this variable?
The instance variables of a class only
The methods of a class only
The instance variables and methods of a class
Which of the following operators are used in conjunction with this and super references?
The new operator
The instanceof operator
The dot operator
Is a constructor automatically called when an object is instantiated?
When may a constructor be called without specifying arguments?
When the default constructor is not called
When the name of the constructor differs from that of the class
When there are no constructors for the class
Which are keywords in Java?
d and e
What are the different modifiers?
public, private, protected, default, static, transient, volatile, final, abstract
What are the different access modifiers?
public, private, protected, default.
What is the difference between instanceof and isInstance?
instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception.
isInstance() determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise.
fgfjhkhlkllopp dgdgd says