Programming





Interview Question and Answers Part 5

Interview Question and Answers Part 5


by Administrator | 31-Mar-2020
Java
 |  1
Tags:  Interview  Question And Answer

Share: 


  1. 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.

  1. All the classes in java.lang package are automatically imported when a program is compiled.

Yes

  1. How can a class be imported to a program?

To import a class, the import keyword should be used as shown: import classname;

  1. How can a class be imported from a package to a program?

import java.packagename.classname (or) import java.packagename.*;

  1. What is a constructor?

A constructor is a special kind of method that determines how an object is initialized when created.

  1. Can Constructors be overloaded like regular methods?

Yes

  1. What is casting?

Casting is used to convert the value of one datatype to another.

  1. Can Boolean values be cast into primitive types?

No

  1. Which casting should be used to convert a larger value into a smaller one?

Explicit cast.

  1. Which of the following features are common to both Java & C++?
    1. The class declaration
    2. The access modifiers
    3. The encapsulation of data & methods within objects
    4. The use of pointers

a,b,c.

  1. Which of the following statements accurately describe the use of access modifiers within a class definition?
    1. They can be applied to both data & methods
    2. They must precede a class's data variables or methods
    3. They can follow a class's data variables or methods
    4. They can appear in any order
    5. They must be applied to data variables first and then to methods

a,b,d

  1. Which of the following statements can be used to describe a public method?
    1. It is accessible to all other classes in the hierarchy
    2. It is accessible only to subclasses of its parent class
    3. It represents the public interface of its class
    4. The only way to gain access to this method is by calling one of the public class methods

a,c. 

  1. Which of the following types of class members can be part of the internal part of a class?
    1. Public instance variables
    2. Private instance variables
    3. Public methods
    4. Private methods

b, d 

  1. Which of the following statements correctly describes the relationship between an object and the instance variable it stores?
    1. Each new object has its own distinctive set of instance variables
    2. Each object has a copy of the instance variables of its class
    3. the instance variable of each object is separate from the variables of other objects
    4. The instance variables of each object are stored together with the variables of other objects

a,b,c.

  1. What are the functions of the dot(.) operator?
    1. It enables you to access instance variables of any objects within a class
    2. It enables you to store values in instance variables of an object
    3. It is used to call object methods
    4. It is to create a new object

a,b,c

  1. Which of the following can be referenced by this variable?
    1. The instance variables of a class only
    2. The methods of a class only
    3. The instance variables and methods of a class

c.

  1. Which of the following operators are used in conjunction with this and super references?
    1. The new operator
    2. The instanceof operator
    3. The dot operator

c

  1. Is a constructor automatically called when an object is instantiated?

Yes

  1. When may a constructor be called without specifying arguments?
    1. When the default constructor is not called
    2. When the name of the constructor differs from that of the class
    3. When there are no constructors for the class

c

  1. Which are keywords in Java?
    1. NULL
    2. sizeof
    3. friend
    4. extends
    5. synchronized

d and e

  1. What are the different modifiers?

public, private, protected, default, static, transient, volatile, final, abstract

  1. What are the different access modifiers?

public, private, protected, default.

  1. 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.


Comments:

Avatar fgfjhkhlkllopp dgdgd says

fgfjhkhlkllopp dgdgdl
Enter a new Comment:










Copyright Šprgrmmng. All rights reserved.