freshers interview papers

Java Classes and Methods interview-questions

1

Classes and Methods

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

a program is compiled.

a)True

b)False

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.

hudihudi.com

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 ().

hudihudi.com

14) Constructors can be overloaded like regular methods.

a)True

b)False

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.

a)True

b)False

Ans: a.

Ref Link contributor : http://www.hudihudi.com/placement/java/java15.htm

Permanent link to Java Tutorials / Java Interview Questions: http://www.freshersinterviewquestions.com/java-classes-and-methods-interview-questions/

Java Operators-interview-questions1

0

Control Statements

1) What are the programming constructs?

Ans: a) Sequential

b) Selection — if and switch statements

c) Iteration — for loop, while loop and do-while loop

hudihudi.com

2) class conditional {

public static void main(String args[]) {

int i = 20;

int j = 55;

int z = 0;

z = i < j ? i : j; // ternary operator System.out.println("The value assigned is " + z); } } What is output of the above program? Ans: The value assigned is 20 hudihudi.com 3) The switch statement does not require a break. a)True b)False Ans: b. hudihudi.com 4) The conditional operator is otherwise known as the ternary operator. a)True b)False Ans: a. 5) The while loop repeats a set of code while the condition is false. a)True b)False Ans: b. hudihudi.com 6) The do-while loop repeats a set of code atleast once before the condition is tested. a)True b)False Ans: a. 7) What are difference between break and continue? Ans: The break keyword halts the execution of the current loop and forces control out of the loop. The continue is similar to break, except that instead of halting the execution of the loop, it starts the next iteration. hudihudi.com 8) The for loop repeats a set of statements a certain number of times until a condition is matched. a)True b)False Ans: a. 9) Can a for statement loop indefinitely? Ans : Yes. 10) What is the difference between while statement and a do statement/ Ans : A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once. Ref Link contributor : http://www.hudihudi.com/placement/java/java13.htm Permanent link to Java Tutorials / Java Interview Questions: http://www.freshersinterviewquestions.com/java-interview-questions1/ .

Go to Top