Classes and Methods

8) All the classes in java.lang package are automatically imported when

a program is compiled.



Ans: a.

9) How can class be imported to a program?

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

import classname;

10) How can class be imported from a package to a program?

Ans: import java . packagename . classname (or) import java.package name.*;

11) What is a constructor?

Ans: A constructor is a special kind of method that determines how an object is

initialized when created.

12) Which keyword is used to create an instance of a class?

Ans: new.

13) Which method is used to garbage collect an object?

Ans: finalize ().

14) Constructors can be overloaded like regular methods.



Ans: a.

15) What is casting?

Ans: Casting is bused to convert the value of one type to another.

16) Casting between primitive types allows conversion of one primitive type to another.



Ans: a.

Ref Link contributor :

Permanent link to Java Tutorials / Java Interview Questions: