0% found this document useful (0 votes)
264 views5 pages

AnswerkeyComputerProgramming PDF

This document contains multiple choice questions testing knowledge of Java fundamentals including classes, objects, inheritance, polymorphism, arrays, and more. It asks about class definitions, constructors, data types, variable scope, exceptions, and other core Java concepts. The majority of questions have a single correct answer regarding syntax, behavior, or output when executing sample code snippets.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
264 views5 pages

AnswerkeyComputerProgramming PDF

This document contains multiple choice questions testing knowledge of Java fundamentals including classes, objects, inheritance, polymorphism, arrays, and more. It asks about class definitions, constructors, data types, variable scope, exceptions, and other core Java concepts. The majority of questions have a single correct answer regarding syntax, behavior, or output when executing sample code snippets.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

What is the result if we execute this: “a” instanceof String; ?

b. true

It is a template for creating an object?


a. Class

It is the method of hiding certain elements of the implementation of a certain class?


a. Encapsulation

What is the result if we execute this: “a”.equals(“a”);?


e. true

What do you call a blueprint of an object?


a. Class

Which of the following show casting object?


b. All of the choices

What will be the value of x if we execute this: String s = "25"; int x = Integer.parseInt(s); ?
e. int 25

Which of the following creates an instance of a class?


b. All of the choices

Which of the following will do implicit cast?


c. short x=1; int y = x;

What do you call a variable that belong to the whole class?


d. Class Method

Which of the following is the correct way to define an interface?


c. public interface [InterfaceName] {}

Which of the following is true about Interface?


a. All of these

It is the ability of an object to have many forms?


b. Polymorphism

Which of the following class declaration is not allowed to be inherited?


d. public abstract class Person {}

What do you call a class that inherits a class?


a. Subclass

What keyword is used to perform class inheritance?


d. extends

Which of the following is the correct way to call the constructor of the parent class?
b. super()

Which of the following method is allowed to be overriden?


a. public final void setName(){}

Which of the following is the correct way to use an interface?


c. public class Person implements [InterfaceName] {}

What is the correct statement to run Java program in command line?


a. java HelloWorld

What is the correct statement to compile Java program in command line?


d. javac HelloWorld.java

What is the extension name of a Java Source code?


a. java

The feature of Java which makes it possible to execute several tasks simultaneously.
e. Multithreaded

Which of the following is a valid identifier?


d. name

What keyword is used to perform class inheritance?


e. extends

Which of the following is true about Runtime errors


c. Runtime errors occur during run-time.

What is the return value of this method: int test(){return 1;} ?


a. 1

What will be the value of x after you execute this statement


d. None of the Choice

What is the output of the code snippet below:


void main(){test(1.0);
test(1);}
void test(double x){
System.out.print(x);
void test(int x){System.out.print(x);}
a. 1.01

What is the maximum index of the array:


int[] intArray = { 1, 2, 3, 5, 6, 7 };
b. 5

What is the length of the array: int[] intArray = { 1, 2, 3, 5, 6, 7 };


d. 6

Which of the following is not a java keyword?


a. name

It used to read values from class variables?


c. Instance Variable

What was the initial name of the Java programming language?


b. Oak

Which of the following does not return numeric value?


c. None of the choices

what will be the output if you execute this code?


int x=2;
switch(x){
case 1:
System.out.print(“1”);
case 2:
System.out.print(“1”);
case 3:
System.out.print(“1”);
default:
System.out.print(“1”);
}
b. display 1111

Which of the following is true about syntax errors:


e. All of the above.

From the array int[] intArray = { 1, 2, 3, 5, 6, 7 };, what is the value of intArray[2]?
c. 3

Which of the following is a valid nexDouble() return value?


c. All of the choices

What will be the output if you execute this code?


do{
System.out.println("Hello World!");
}
while(true);
d. print "Hello World" infinitely

What is the function of JVM?


c. Interpreting bytecode

Which of the following shows a valid Overloading method?


a. None of the choices

What is the index number of the last element of an array with 20 elements?
d. 19

Which of the following is a valid statement to accept int input? Let us assume that we have
declared scan as Scanner.
b. int num = scan.nextInt();

What will be the value of x after executing this code for(int x=0; x<=11; x++) {} is run?
c. 12

Which of the following shows Overloading method?


d. void test(int x){} void test(double x){}

What is floating-point literal?


a. All of the choices

What did java generates after compiling the java source code?
b. Byte Code

What is the name of this method: int test(){return 1;} ?


d. test

Which of the following is not a primitive data type?


e. String
Which of the following is not a valid Float value?
e. all of the choices

The Java feature, "write once, run anywhere", is termed as


c. Platform independent

What is the output of the code snippet below:


int[] intArray = { 1, 2, 3, 5, 6, 7 };
for(int x = intArray.length-1; x>=0; x--){
System.out.print(intArray[x]);
}
c. 765321

Which of the following is a valid multidimensional array?


a. All of the choice

Which of the following is true about constructor?


b. It can only be called by using the new operator during class instantiation.

You might also like