Oops
Oops
Oops
A) A
Int I = 0;
I = i++ + I;
System.out.println(“I = ” +i);
A) B
(b) A private member of a class cannot be accessed by the methods of the same class.
(d) A protected member of a class can be accessed from its derived class.
A) B
(a) Static (b) const (c) final (d) abstract € none of the above.
A) C
(d) A class must be qualified as ‘abstract’ class, if it contains one abstract method.
A) C
7) The fields in an interface are implicitly specified as,
Static int I = 1;
System.out.println(i+” , “);
M(i);
System.out.println(i);
I += 2;
A) C
(b) A class which is implementing an interface must implement all the methods of the interface.
A) C
(a) A finally block is executed before the catch block but after the try block.
(b) A finally block is executed, only after the catch block is executed.
A) C
© ‘0’
(d) Both (A) and (B) above € (A), (B) and (C) above.
A) D
R1.setColor(Color.blue);
Rectangle r2 = r1;
R2.setColor(Color.red);
After the above piece of code is executed, what are the colors of r1 and
(a) Color.blue
Color.red
(b) Color.blue
Color.blue
© Color.red
Color.red
(c) Color.red
Color.blue
A) C
13) What is the type and value of the following expression? (Notice the integer division)
-4 + ½ + 2*-3 + 5.0
© int -4
A) D
13) What is printed by the following statement?
System.out.print(“Hello,\nworld!”);
A) C
S = “Yellow”;
A=a+2;
Return a;
Int a=3;
String s = “Blue”;
A = foo(a,s);
System.out.println(“a=”+a+” s=”+s);
Bar();
A) D
15) Which of the following variable declaration would NOT compile in a java program?
(a) Int var; (b) int VAR; (c) int var1; (d) int var_1; € int 1_var;.
A) E
// Other methods…
The method setValue assigns the value of I to the instance field value. What could you write for the
implementation of setValue?
(d) Both (A) and (B) and above € (A), (B) and (C) above.
A) D
17) Which of the following is TRUE?
(d) A class has always a constructor (possibly automatically supplied by the java compiler).
A) D
18) A constructor
(a) Must have the same name as the class it is declared within.
A) E
19) Consider,
Public MyClass(){/code/}
// more code…
© MyClass mc = MyClass;
A) A
Java Multiple Choice Questions 21) What is byte code in the context of Java?
A) A
Java Multiple Choice Questions 22) What is garbage collection in the context of Java?
(a) The operating system periodically deletes all the java files available on the system.
(b) Any package imported in a program and not used is automatically deleted.
© When all references to an object are gone, the memory used by the object is automatically reclaimed.
(d) The JVM checks the output of any Java program and deletes anything that doesn’t make sense.
€ Janitors working for Sun Micro Systems are required to throw away any Microsoft documentation
found in the employees’ offices.
A) C
Java Multiple Choice Questions 23) You read the following statement in a Java program that compiles
and executes.
Submarine.dive(depth);
A) B
Java Multiple Choice Questions 24) The java run time system automatically calls this method while
garbage collection.
A) B
Java Multiple Choice Questions 25) The correct order of the declarations in a Java program is,
A) A
© The same method name and same number and type of parameters with different return type
A) D
Java Multiple Choice Questions 27) A protected member can be accessed in,
(a) a subclass of the same package (b) a non-subclass of the same package
A) C
Java Multiple Choice Questions 28) What is the output of the following code:
Class eq
{
Public static void main(String args[])
String s1 = “Hello”;
System.out.println(s1==s2);
A) B
Java Multiple Choice Questions 29) All exception types are subclasses of the built-in class
A) D
Java Multiple Choice Questions 30) When an overridden method is called from within a subclass, it will
always refer to the version of that method defined by the
(b) Subclass
A) B
Java Multiple Choice Questions With Answers
Java Multiple Choice Questions 31) Mark the incorrect statement from the following:
(a) Java is a fully object oriented language with strong support for proper software engineering
techniques
A) D
€ Default constructor.
A) C
Java Multiple Choice Questions 33) Which of the following is not a component of Java Integrated
Development Environment (IDE)?
A) C
Java Multiple Choice Questions 34) Identify, from among the following, the incorrect variable name(s).
€ my2ndFont.
A) C
Java Multiple Choice Questions 35) Use the following declaration and initialization to evaluate the Java
expressions
Int a = 2, b = 3, c = 4, d = 5;
Float k = 4.3f;
System.out.println( – -b * a + c *d – -);
A) B
Java Multiple Choice Questions 36) Use the following declaration and initialization to evaluate the Java
expressions
Int a = 2, b = 3, c = 4, d = 5;
Float k = 4.3f;
System.out.println(a++);
(a) 3 (b) 2 (c) 4 (d) 10 € Synatax error.
A) B
Java Multiple Choice Questions 37) Use the following declaration and initialization to evaluate the Java
expressions
Int a = 2, b = 3, c = 4, d = 5;
Float k = 4.3f;
A) E
Java Multiple Choice Questions 38) Use the following declaration and initialization to evaluate the Java
expressions
Int a = 2, b = 3, c = 4, d = 5;
Float k = 4.3f;
System.out.println (c=c++);
A) B
Java Multiple Choice Questions 39) Consider the following Java program :
Class IfStatement{
If (a==3)
If (b==3)
System.out.println(“===============”);
Else
System.out.println(“#################”);
System.out.println(“&&&&&&&&&&&”);
(a) ===============
(b) #################
&&&&&&&&&
© &&&&&&&&&&&
(d) ===============
&&&&&&&&&&
€ ################.
A) C
(d) Applet viewer tool which comes, with the Java Development Kit.
€ Jbuilder.
A) D
Class test{
I *= 2;
I /= 2;
Class argumentPassing
Ob.meth(a,b);
}
Core Java Multiple Choice Questions With Answers
41) What would the output be of the above Program – III before and after it is called?
A) C
42) What would the argument passing method be which is used by the above Program – III?
€ Call by compiler.
A) A
Class prob1{
Int result;
If (n==1)
Return 1;
Result = puzzel(n-1) * n;
Return result;
Class prob2{
A) D
44) The blank space in the following sentence has to be correctly filled :
45) Java compiler javac translates Java source code into ………………………
A) B
(a) System cells (b) Keywords (c) Comments (d) Control structures € Blocks.
A) C
47) In Java, a character constant’s value is its integer value in the.........................character set.
A) B
A) D
49) An abstract data type typically comprises a …………… and a set of..................respectively.
(a) Data representation, classes (b) Database, operations
A) E
50) In object-oriented programming, the process by which one object acquires the properties of
another object is called
A) D
51) Re-implementing an inherited method in a sub class to perform a different task from the parent
class is called
A) E
52) In a class definition, the special method provided to be called to create an instance of that class is
known as a/an
A) C
53) Consider the following statements about Java packages:
I. Packages don’t provide a mechanism to partition all class names into more
manageable chunks.
II. Packages provide a visibility control mechanism.
III. One of the important properties of a package is that all classes defined inside a
package is accessible by code outside that package.
IV. The .class files for classes declared to be part of a package can be stored in multiple
directories.
A) B
(a) Both (I) and (II) above (b) Both (III) and (IV) above
© Both (I) and (III) above (d) Both (II) and (IV) above
A) E
55) Identify, from among the following, the incorrect descriptions related to Java :
(a) Java Virtual Machine translates byte code into its own system’s machine language and runs the
resulting machine code
(b) The arithmetic operations *, /, %, + and – have the same level of precedence
© Comments do not cause any action to be performed during the program execution
(d) All variables must be given a type when they are declared
A) B
(a) Both (I) and (III) above (b) Both (II) and (IV) above
© Both (I) and (II) above (d) (III) and (IV) above
A) D
(a) Both (I) and (II) above (b) (I), (II), (III) and (IV) above
© (I), (II) and (III) above (d) (II) and (III) above
A) C
58) For what values respectively of the variables gender and age would the Java expression gender == 1
&& age >= 65 become true?
A) C
Int result, x ;
X=1;
Result = 0;
If (x%2 == 0) result + = x ;
++x;
}
System.out.println(result) ;
A) B
(d) Ready, running and sleeping are three states that a thread can be in during its life cycle
A) D
€ Object persistence.
A) C
© An object is a variable
A) B
(d) The organization of components interacting not to achieve a coherent common behavior
A) B
5) Which of the following does not belong: If a class inherits from some other class,
it should
(b) Over-ride or add the minimum to accomplish the derived class’ purpose
A) C
(d) inheritance does not describe any kind of relationship between classes
€ “contains” of relationship.
A) A
A) A
8) Polymorphism
(b) Refers to the ability of two or more objects belonging to different classes to respond to exactly the
same message in different class-specific ways
€ Refers to the ability of two or more objects belonging to different classes to respond to exactly the
same message in different class-specific ways and simplifies code maintenance.
A) E
A) D
10) Given a class named student, which of the following is a valid constructor declaration for
the class?
A) A
Core Java Multiple Choice Questions With Answers
(a) The operating system periodically deletes all of the java files available on the system.
(b) Any package imported in a program and not used is automatically deleted.
© When all references to an object are gone, the memory used by the object is automatically reclaimed.
(d) The JVM checks the output of any Java program and deletes anything that doesn’t make sense.
€ When all references to an object are gone the memory used by the object is not reclaimed.
A) C
(a) Only (II) (b) (I) and (II) (c) (II) and (III)
A) C
(d) To force developers to extend the class not to use its capabilities
Abstract class xy
€ No error.
A) C
15) Which of these field declarations are legal within the body of an interface?
(a) Private final static int answer = 42 (b) public static int answer=42
€ No error.
A) B
A) D
17) A method within a class is only accessible by classes that are defined within the same
package as the class of the method. Which one of the following is used to enforce
such restriction?
A) D
18) Basic Java language functions are stored in which of the following java package?
A) A
A) B
A) B
Core Java Multiple Choice Questions # 21) What is the fundamental unit of information of writer
streams?
A) A
Core Java Multiple Choice Questions # 22) File class is included in which package?
€ java.util.package.
A) A
String s1 = ” yes” ;
String s2 = ” yes ” ;
A) A
A) D
Core Java Multiple Choice Questions # 25) What is the sequence of major events in the life of an applet?
(a) init, start, stop, destroy (b) start, init , stop , destroy
A) A
Core Java Multiple Choice Questions # 26) Which of the following is true in regard to applet execution?
(a) Applets loaded from the same computer where they are executing have the same restrictions as
applets loaded from the network.
(b) Applets loaded and executing locally have none of the restrictions faced by applets that get loaded
from the network.
© Applets loaded and executing locally have some restrictions faced by applets that get loaded from the
network.
A) B
Core Java Multiple Choice Questions # 27) What is the return type of the method getID() defined in
AWTEvent class
A) A
Core Java Multiple Choice Questions # 28) Which of the following events will cause a thread to die?
A) D
Core Java Multiple Choice Questions # 29) What will be the result of the expression 13 & 25?
A) C
Core Java Multiple Choice Questions # 30) Which of the following statements are true regarding the
finalize( ) method?
(b) The compiler will fail to compile the code that explicitly tries to call the finalize( ) method
© The body of the finalize ( ) method can only access other objects that are eligible for garbage
collection
A) D
Core Java Multiple Choice Questions # 31) Which one of these is a valid method declaration?
(a)
Void method1
(b)
Void method2()
Void method3(void)
(d)
Method4()
Methods(void).
A) B
Core Java Multiple Choice Questions # 32) Given a class named Book, which one of these is a valid
constructor declaration for the class?
(a)
Book(Book b) { }
(b)
Book Book() { }
(d)
Void Book() { }
Abstract Book() { }.
A) A
Core Java Multiple Choice Questions # 33) What will be the result of attempting to compile the following
program?
Long var;
MyClass a,b;
}
(a)
A compilation ERROR will occur at (1), since constructors cannot specify a return value
(b)
A compilation error will occur at (2), since the class does not have a default constructor
A compilation error will occur at (3), since the class does not have a constructor which takes one
argument of type int
(d)
A) C
Core Java Multiple Choice Questions # 34) Given the following class, which of these is valid way of
referring to the class from outside of the package net.basemaster?
Package net.basemaster;
// . . .
(a)
(b)
A) C
Core Java Multiple Choice Questions # 35) Which one of the following class definitions is a valid
definition of a class that cannot be instantiated?
(a)
Class Ghost
(b)
Void haunt();
Void haunt() { };
(d)
Abstract Ghost
Abstract haunt();
A) C
36) Which one of the following class definitions is a valid definition of a class that cannot be extended?
(a)
Class Link { }
(b)
(d)
A) E
37) Given the following definition of a class, which fields are accessible from outside the package
com.corporation.project?
Package com.corporation.project;
Int I;
Public int j;
Protected int k;
Private int l;
(a)
(b)
(d)
A) B
38) How restrictive is the default accessibility compared to public, protected, and private accessibility?
(a)
Less restrictive than public
(b)
(d)
Less restrictive than protected from within a package, and more restrictive than protected from outside
a package.
A) C
(a)
Private members are always accessible from within the same package
(b)
Private members can only be accessed by code from within the class of the member
A member with default accessibility can be accessed by any subclass of the class in which it is defined
(d)
Package/default accessibility for a member can be declared using the keyword default.
A) B
If no accessibility modifier (public, protected, and private) is specified for a member declaration, the
member is only accessible for classes in the package of its class and subclasses of its class anywhere
(b)
You cannot specify accessibility of local variables. They are only accessible within the block in which they
are declared
Subclasses of a class must reside in the same package as the class they extend
(d)
A) B