1.
What is the size of a Char?
Correct Answer
D. 16 bits
2.
A class cannot be declared
Correct Answer
B. Private
3.
Following code will result in: int a = 3.5;
Correct Answer
A. Compilation error
4.
Following code will result in: int a = 9/0;
Correct Answer
B. Runtime Exception
5.
Following code will result in: class A { int b = 1; public static void main(String [] args) { System.out.println("b is " + b); }}
Correct Answer
A. Compilation error
6.
Following code will result in: class A { public static void main(String [] args) {B a = new A(); }} class B extends A {}
Correct Answer
A. Compile error
7.
Following code will result in: class A { public static void main(String [] args) {A a = new B(); }} class B extends A {}
Correct Answer
B. No errors
8.
Methods that are marked protected can be called in any subclass of that class.
Correct Answer
A. True
9.
A static class can have non-static methods
Correct Answer
A. True
10.
What is old name of "Java"
Correct Answer
A. OAK
11.
What is the use of "this " keyword
Correct Answer
B. To refer current object
12.
Can you compare a boolean to an integer?
Correct Answer
B. No
13.
If class A implements an interface does it need to implement all methods of that interface?
Correct Answer
B. No, not when A is abstract
14.
Integer a = new Integer(2); Integer b = new Integer(2); What happens when you do if (a==b)?
Correct Answer
B. FALSE
15.
Inner classes can be defined within methods
Correct Answer
A. True
16.
The default statement of a switch is always executed
Correct Answer
B. False
17.
What is Java (in regard to Computer Science) ?
Correct Answer
B. AN OBJECT-ORIENTED PROGRAMMING LANGUAGE
18.
WHAT IS USE OF SUPER KEYWORD
Correct Answer
A. TO CALL SUPER CLASS CONSTRUCTOR
19.
Java runs on _______.
Correct Answer
B. All of the Above
20.
What is the main function of any variable ?
Correct Answer
B. To keep track of data in the memory of the computer
21.
What is the proper way to declare a variable ?
Correct Answer
B. VariableType variableName;
22.
Booleans are _______.
Correct Answer
A. True or False
23.
The following statements make “index and length” be what number ?int a[]=new int[20];
Correct Answer
A. 19,20
24.
What is an assignment statement ?
Correct Answer
B. Assigning a value to a variable
25.
What is use of final keyword
Correct Answer
B. To make a constant variable
26.
If you want your conditional to depend on two conditions BOTH being true, what is the proper notation to put between the two Boolean statements ?
Correct Answer
A. &&
27.
Which of the following means that in order for the conditional to happen, either x must be less than 3 or y must be greater than or equal to 4 ?
Correct Answer
A. if ((x < 3) || (y > = 4))
28.
What is a loop ?
Correct Answer
B. A segment of code to be run a specified amount of times
29.
What is essential in making sure that your loop is not infinite ?
Correct Answer
B. That your Boolean statement will at some point be false
30.
Which is NOT a section of all types of loops ?
Correct Answer
B. The word "while"
31.
In a ‘for’ loop, what section of the loop is not included in the parentheses after “for” ?
Correct Answer
A. Loop Body
32.
What is a function in terms of Computer Science ?
Correct Answer
A. A group of code lines that performs a specific task
33.
What does JVM stands for ?
Correct Answer
A. Java Virtual Machine
34.
Which is right way to creating an array of integer in java?
Correct Answer
C. Int[] javaArray = new int[10];
35.
Which keyword is used to inherit class?
Correct Answer
B. Extends
36.
Which of the java classes that cannot be subclassed?
Correct Answer
C. Final class
37.
Can we declare abstract static method?
Correct Answer
B. No
38.
Which type of inheritance is not supported by java?
Correct Answer
B. Multiple
39.
Java final methods cannot be overridden but overloaded?
Correct Answer
A. True
40.
Given the below class definitions
class Base
{
void display ()
{
System.out.println("Base"); }
}
class Derived extends Base
{
void display ()
{ System.out.println("Derived"); }
}
and objects
Base b = new Base();
Derived d = new Derived();
Base bd = new Derived();
then the print statements
System.out.print(b.display() + " ");
System.out.print(d.display() + " ");
System.out.print(bd.display() + " ");
System.out.println();
will display:
Correct Answer
B. Base Derived Derived
41.
Which of the following are primitive types?
Correct Answer
A. Byte
42.
Which of the following statements accurately describe the use of access modifiers(private,public,protected) within a class definition?
Correct Answer(s)
A. They can be applied to both data & methods
B. They must precede a class's data variables or methods
D. They can appear in any order
43.
Which of the following statements correctly describes the relation between an object and the instance variable it stores?
Correct Answer(s)
A. Each new object has its own distinctive set of instance variables
B. Each object has a copy of the instance variables of its class
C. The instance variable of each object are seperate from the variables of other objects
44.
What is the size of int in java
Correct Answer
B. 4 bytes
45.
Which of the following is true about class defination in a file
Correct Answer
D. All of above
46.
What is the output of following code
int x[]={1,2,3,4};
Sytem.out.println(" Index at 4 is "+x[4]);
Correct Answer
A. IndexOutOfBoundException
47.
Given the below code. What is the result?
class Test
{
public static void main(String args[]) {
String str = "null";
if (str == null) {
System.out.print("1");
} else if (str.length() == 0) {
System.out.print("2");
} else {
System.out.print("3");
}
}
}
Correct Answer
D. "3" is printed.
48.
In the below code which can directly access and change the value of the variable id?
package com.cisco.mycompany;
public class Company {
private int id = 100;
}
Correct Answer
A. Only the Company class
49.
Given the code. What is the result after the class TryMe execution?
class A {
public void doA() {
B b = new B();
b.dobB();
System.out.print("doA");
}
}
class B {
public void dobB() {
C c = new C();
c.doC();
System.out.print("doB");
}
}
class C {
public void doC() {
if (true)
throw new NullPointerException();
System.out.print("doC");
}
}
public class TryMe {
public static void main(String args[]) {
try {
A a = new A();
a.doA();
} catch (Exception ex) {
System.out.print("error");
}
}
}
Correct Answer
D. "error" is printed
50.
Given the code. What is the result if NullPointerException occurs at line 2?
1. try {
2. //some code goes here
3. }
4. catch (NullPointerException ne) {
5. System.out.print("1 ");
6. }
7. catch (RuntimeException re) {
8. System.out.print("2 ");
9. }
10. finally {
11. System.out.print("3");
12. }
Correct Answer
C. 1 3