
























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
interview questions
Typology: Slides
1 / 64
This page cannot be seen from the preview
Don't miss anything!

























































Q. No. 1
which statement is true about a method? Select the one correct answer.
A. A method is an implementation of an abstraction. B. A method is an attribute defining the property of a particular abstraction. C. A method is a category of objects. D. A method is an operation defining the behavior for a particular abstraction. E. A method is a blueprint for making operations.
Q. No. 2
Which statement is true about an object? Select the one correct answer. A. An object is what classes are instantiated from. B. An object is an instance of a class. C. An object is a blueprint for creating concrete realization of abstractions. D. An object is a reference to an attribute. E. An object is a variable.
Q. No. 3
Which line contains a constructor in this class definition? public class Counter { // (1)
int current, step;
public Counter(int startValue, int stepValue) { // (2)
set(startValue); setStepValue(stepValue); }
public int get() { return current; } // (3)
public void set(int value) { current = value; } // (4)
public void setStepValue(int stepValue) { step = stepValue; } // (5)
}
Select the one correct answer.
A. Code marked with (1) is a constructor. B. Code marked with (2) is a constructor. C. Code marked with (3) is a constructor. D. Code marked with (4) is a constructor. E. Code marked with (5) is a constructor. Q. No. 4
Given that Thing is a class, how many objects and how many reference variables are created by the following code? Thing item, stuff; item = new Thing(); Thing entity = new Thing(); Select the two correct answers. a. One object is created. b. Two objects are created. c. Three objects are created. d. One reference variable is created. e. Two reference variables are created. f. Three reference variables are created.
Q. No. 5
Which statement is true about an instance method?
Q. No. 7
Given the following code, which statements are true? class A { int value1; }
class B extends A { int value2; } Select the two correct answers. a. Class A extends class B. b. Class B is the superclass of class A. c. Class A inherits from class B. d. Class B is a subclass of class A. e. Objects of class A have a field named value2. f. Objects of class B have a field named value1.
Q. No. 8
What command in the Java 2 SDK should be used to compile the following code contained in a file called SmallProg.java? public class SmallProg { public static void main(String[] args) { System.out.println("Good luck!"); } } Select the one correct answer. a. java SmallProg b. javac SmallProg c. java SmallProg.java d. javac SmallProg.java e. java SmallProg main
Q. No. 9
What command in the Java 2 SDK should be used to compile the following code contained in a file called SmallProg.java? public class SmallProg {
public static void main(String[] args) { System.out.println("Good luck!"); } } Select the one correct answer. a. java SmallProg b. javac SmallProg c. java SmallProg.java d. javac SmallProg.java e. java SmallProg main
Q. No. 10
Which of the following is not a legal identifier? Select the one correct answer. a. a2z b. ödipus c. 52pickup d. _class e. ca$h f. total#
Q. No. 11
Which statement is true? Select the one correct answer. a. new and delete are keywords in the Java language. b. try, catch, and thrown are keywords in the Java language. c. static, unsigned, and long are keywords in the Java language. d. exit, class, and while are keywords in the Java language.
d. "hello" e. false Q. No. 14
Which of the following primitive data types are not integer types? Select the three correct answers. a. Type boolean b. Type byte c. Type float d. Type short e. Type double Q. No. 15
Which integral type in Java has the exact range from -2147483648 (-2^31 ) to 2147483647 (2^31 -1), inclusive? Select the one correct answer. a. Type byte b. Type short c. (^) Type int d. Type long e. Type char
Q. No. 16
Which of the following lines are valid declarations? Select the three correct answers. a. char a = '\u0061'; b. char 'a' = 'a'; c. char \u0061 = 'a'; d. ch\u0061r a = 'a'; e. ch'a'r a = 'a';
Q. No. 17
Given the following code within a method, which statement is true? int a, b; b = 5; Select the one correct answer. a. Local variable a is not declared. b. (^) Local variable b is not declared. c. Local variable a is declared but not initialized. d. Local variable b is declared but not initialized. e. Local variable b is initialized but not declared.
Q. No. 18
In which of these variable declarations will the variable remain uninitialized unless explicitly initialized? Select the one correct answer. a. Declaration of an instance variable of type int. b. Declaration of a static variable of type float. c. Declaration of a local variable of type float. d. Declaration of a static variable of type Object. e. Declaration of an instance variable of type int[]. Q. No. 19
Select the three correct answers. a. public b. static c. void d. (^) main e. String f. args Q. No. 22
Given char c = 'A'; What is the simplest way to convert the character value in c into an int? Select the one correct answer. a. int i = c; b. int i = (int) c; c. int i = Character.getNumericValue(c);
Q. No. 23
What will be the result of attempting to compile and run the following class? public class Assignment { public static void main(String[] args) { int a, b, c; b = 10; a = b = c = 20; System.out.println(a); } } Select the one correct answer. a. The code will fail to compile, since the compiler will recognize that the variable c in the assignment statement a = b = c = 20; has not been initialized. b. The code will fail to compile because the assignment statement a = b = c = 20; is illegal. c. The code will compile correctly and will display 10 when run. d. The code will compile correctly and will display 20 when run. Q. No. 24
What will be the result of attempting to compile and run the following program? public class MyClass { public static void main(String[] args) { String a, b, c; c = new String("mouse");
a = new String("cat"); b = a; a = new String("dog"); c = b; System.out.println(c); } } Select the one correct answer. a. The program will fail to compile. b. The program will print mouse when run. c. The program will print cat when run. d. The program will print dog when run. e. The program will randomly print either cat or dog when run.
Q. No. 25
Which of the following expressions will be evaluated using floating-point arithmetic? Select the three correct answers. a. 2.0 * 3. b. 2 * 3 c. 2/3 + 5/ d. 2.4 + 1. e. 0x10 * 1L * 300.
Q. No. 26
What is the value of the expression (1 / 2 + 3 / 2 + 0.1)? Select the one correct answer. a. 1 b. 1. c. 1. d. 2 e. 2.
d. (--1) e. (1 * * 1) f. (- -1)
Q. No. 29
What is the value of evaluating the following expression (- -1-3 * 10 / 5-1)? Select the one correct answer. a. – b. – c. 7 d. 8 e. 10 f. (^) None of the above.
Q. No. 30
Which of these assignments are valid? Select the four correct answers. a. short s = 12; b. long l = 012; c. (^) int other = (int) true; d. float f = -123; e. double d = 0x12345678; Q. No. 31
What will be the result of attempting to compile and run the following program? public class MyClass { public static void main(String[] args) { RuntimeException re = null; throw re; } } Select the one correct answer. a. The code will fail to compile, since the main() method does not declare that it throws RuntimeException in its declaration. b. The program will fail to compile, since it cannot throw re. c. The program will compile without error and will throw java.lang.RuntimeException when run. d. The program will compile without error and will throw java.lang.NullpointerException when run. e. The program will compile without error and will run and terminate without any output.
Q. No. 32
Which statements are true? Select the three correct answers. a. The result of the expression (1 + 2 + "3") would be the string "33". b. The result of the expression ("1" + 2 + 3) would be the string "15". c. The result of the expression (4 + 1.0f) would be the float value 5.0f. d. The result of the expression (10/9) would be the int value 1. e. The result of the expression ('a' + 1) would be the char value 'b'.
Q. No. 33
What happens when you try to compile and run the following program? public class Prog1 { public static void main(String[] args) { int k = 1; int i = ++k + k++ + + k; System.out.println(i); } } Select the one correct answer. a. The program will not compile. The compiler will complain about the expression ++k + k ++ + + k.
} Select the one correct answer. a. The compiler will refuse to compile it, since you cannot assign a byte to an int without a cast. b. The program will compile and will print 128 when run. c. The compiler will refuse to compile it, since 128 is outside the legal range of values for a byte. d. (^) The program will compile, but will throw a ClassCastException when run. e. The program will compile and will print 255 when run. Q. No. 36
What will the following program print when run? public class EvaluationOrder { public static void main(String[] args) { int[] array = { 4, 8, 16 }; int i=1; array[++i] = --i; System.out.println(array[0] + array[1] + array[2]); } } Select the one correct answer. a. 13 b. 14 c. 20 d. 21 e. 24
Q. No. 37
Which of the following expressions evaluates to true? Select the two correct answers. a. (false | true) b. (null != null) c. (4 <= 4) d. (!true) e. (true & false)
Q. No. 38
Which statements are true? Select the two correct answers. a. The remainder operator % can only be used with integral operands. b. Identifiers in Java are case insensitive. c. The arithmetic operators *, /, and % have the same level of precedence. d. A short value ranges from -128 to +127 inclusive. e. (+15) is a legal expression.
Q. No. 39
Which statements are true about the lines of output printed by the following program? public class BoolOp { static void op(boolean a, boolean b) { boolean c = a != b; boolean d = a ^ b; boolean e = c == d; System.out.println(e); } public static void main(String[] args) { op(false, false); op(true, false); op(false, true); op(true, true); } } Select the three correct answers. a. All lines printed are the same. b. At least one line contains false. c. At least one line contains true. d. The first line contains false.
/* // / Select the one correct answer. d. No, the block comment (/ ... */) is not ended since the single-line comment (// ...) comments out the closing part. e. It is a completely valid comment. The // part is ignored by the compiler. f. This combination of comments is illegal and the compiler will reject it.
Q. No. 3
Which of the following do not denote a primitive data value in Java? Select the two correct answers. f. "t" g. 'k' h. 50.5F i. "hello" j. false Q. No. 4
Which of the following primitive data types are not integer types? Select the three correct answers. f. (^) Type boolean
g. Type byte h. Type float i. Type short j. Type double Q. No. 5
Which integral type in Java has the exact range from -2147483648 (-2^31 ) to 2147483647 (2^31 -1), inclusive? Select the one correct answer. f. Type byte g. Type short h. Type int i. Type long j. Type char
Q. No. 6
Which of the following lines are valid declarations? Select the three correct answers. f. char a = '\u0061'; g. char 'a' = 'a'; h. char \u0061 = 'a'; i. ch\u0061r a = 'a'; j. ch'a'r a = 'a';
Q. No. 7
Given the following code within a method, which statement is true? int a, b; b = 5; Select the one correct answer.