0% found this document useful (0 votes)
321 views24 pages

Comprog 2 Finals

The document contains a multiple choice quiz on Java programming concepts. It consists of 34 questions related to topics like classes, methods, arrays, loops, exceptions, data types, and more. For each question, the user selects an answer and receives feedback on whether it is correct or incorrect, along with a score.

Uploaded by

mark gonzales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
321 views24 pages

Comprog 2 Finals

The document contains a multiple choice quiz on Java programming concepts. It consists of 34 questions related to topics like classes, methods, arrays, loops, exceptions, data types, and more. For each question, the user selects an answer and receives feedback on whether it is correct or incorrect, along with a score.

Uploaded by

mark gonzales
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

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

Select one:
a. public abstract class Person {}
b. class Person{}
c. public class Person {}

d. public final class Person {} 


Feedback

Your answer is correct.

Question 2
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. 12 
b. 10
c. 11

d. 1
Feedback

Your answer is correct.

Question 3
Correct
Mark 1.00 out of 1.00

Flag question
Question text

Which of the following shows a valid Overloading method? 

Select one:
a. None of the choices 
b. void test(char x, int y){} void test(int x, char y){}
c. void test(int x){} void test(int y){}
d. All of the Choices

e. void test(){} void test(){}


Feedback

Your answer is correct.

Question 4
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What did java generates after compiling the java source code?

Select one:
a. Executable file
b. Image file
c. None of the choices
d. Byte Code 
e. Class Code

Question 5
Correct
Mark 1.00 out of 1.00
Flag question

Question text

What is the function of JVM?

Select one:
a. Reading bytecode
b. Interpreting bytecode 

c. Generating bytecode
Feedback

Your answer is correct.

Question 6
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is true about syntax errors:

Select one:
a. None of the choices
b. Incorrect capitalization leads to syntax error.
c. You will have syntax errors if you misspell the Java command.
d. All of the above. 
e. Syntax errors are usually typing errors.

Question 7
Correct
Mark 1.00 out of 1.00
Flag question

Question text

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

Select one:
a. java HelloWorld
b. javac HelloWorld
c. javac HelloWorld.java 

d. java HelloWorld.java
Feedback

Your answer is correct.

Question 8
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

What will be the output if you execute this code:


int a[] = new int[1];
System.out.println(a[1]);

Select one:
a. It will display the value of a[1].
b. It will produce an exception.
c. It will display “a[1]”.

d. It will display nothing. 


Feedback
Your answer is incorrect.

Question 9
Correct
Mark 2.00 out of 2.00

Flag question

Question text

Which of the following is true about constructor?

Select one:
a. It can only be called by using the new operator during class instantiation.
b. Constructors does not have any return value
c. All of the choices 
d. Constructors have the same name as the class

Question 10
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What is floating-point literal?

Select one:
a. It could be double or float value.
b. An integer literal with decimal point.
c. Can be express in scientific notation.
d. By default it is double type.
e. All of the choices 

Question 11
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is the correct syntax to define a method?

Select one:
a. package <packageName>; 
b. <packageName> package;
c. <modifier> package <packageName>;

d. <packageName>;
Feedback

Your answer is correct.

Question 12
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following scenarios where an exception may occur?

Select one:
a. All of the choices 
b. A user has entered an invalid data.
c. A network connection has been lost in the middle of communications or the JVM has run
out of memory.
d. A file that needs to be opened cannot be found.

Question 13
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. Robust
b. Platform independent
c. Multithreaded 
d. Code Security
e. None of the choices

Question 14
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. int
b. test
c. return 1

d. 1 
Feedback

Your answer is correct.

Question 15
Correct
Mark 2.00 out of 2.00

Flag question

Question text

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]);
}
 

Select one:
a. 765321 
b. The given code is not valid
c. 12356

d. 123567
Feedback

Your answer is correct.

Question 16
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

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);}

Select one:
a. 1.0
b. 1.01
c. 1.01.0

d. 11 
Feedback

Your answer is incorrect.

Question 17
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What do you call a blueprint of an object?

Select one:
a. Constructor
b. one of the choice
c. Class 
d. Object
e. Method

Question 18
Correct
Mark 1.00 out of 1.00

Flag question
Question text

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

Select one:
a. Platform independent 
b. Robust
c. Object Oriented

d. High Performance
Feedback

Your answer is correct.

Question 19
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is true about Runtime errors

Select one:
a. Runtime errors occur when there is a design flaw in your program
b. Runtime errors occur after compilation.
c. All of the choices
d. Runtime errors occur during run-time. 

Question 20
Correct
Mark 1.00 out of 1.00

Flag question

Question text
What will be the output if you execute this code?
do{
System.out.println("Hello World!");
}
while(true);

Select one:
a. print "Hello World"
b. print "Hello World" infinitely 
c. The code will not run because of syntax error

d. Do nothing
Feedback

Your answer is correct.

Question 21
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following does not return numeric value?

Select one:
a. nextDouble()
b. nextLong()
c. nextShort()
d. nextInt()

e. None of the choices 


Feedback

Your answer is correct.

Question 22
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. 6
b. test 
c. int

d. 7
Feedback

Your answer is correct.

Question 23
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. Encapsulation 
b. Class
c. Object Oriented
d. None of the choices
e. Object

Question 24
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What keyword is used to perform class inheritance?

Select one:
a. implements
b. None of the choices
c. inherits
d. derives
e. extends 

Question 25
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following shows Overloading method? 

Select one:
a. void test(){} void test(){}
b. void test(int x){} void test(double x){} 
c. All of the Choices

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


Feedback

Your answer is correct.

Question 26
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. 21
b. 0
c. None of the choices
d. 19 
e. 20

Question 27
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is not a valid Float value?

Select one:
a. all of the choices 
b. 1.2345E+3
c. 3.4028235E+38F
d. 12345678910F

e. 2.23
Feedback

Your answer is correct.


Question 28
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. floating-point literal
b. 3.1416
c. double value
d. 12.0

e. All of the choices 


Feedback

Your answer is correct.

Question 29
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is not a primitive data type?

Select one:
a. String 
b. none of the choices
c. short
d. byte
e. long

Question 30
Correct
Mark 1.00 out of 1.00

Flag question

Question text

It used to read values from class variables?

Select one:
a. Instance Variable
b. Accessor 
c. Method
d. None of the choices
e. Mutator

Question 31
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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


int z=0;  
for(int x=0; x<10; x++)
for(int y=0; y<x; y++) z*=(x*y);

Select one:
a. None of the Choice 
b. 512
c. 128
d. 1

e. 236
Feedback

Your answer is correct.

Question 32
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

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”);
}

Select one:
a. display 1
b. display 111
c. display 1234

d. display 1111 
Feedback

Your answer is incorrect.

Question 33
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

Which of the following is a valid editor for java source code?

Select one:
a. NetBeans
b. All of the choices
c. eclipse
d. BlueJ
e. Notepad 

Question 34
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. 7
b. 5
c. 6 

d. 4
Feedback

Your answer is correct.

Question 35
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is not a java keyword?

Select one:
a. goto
b. None of the choices
c. if
d. else
e. name 

Question 36
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. true 
b. false
c. “a”

d. The code is not valid


Feedback

Your answer is correct.

Question 37
Not answered
Marked out of 1.00

Flag question

Question text

Which of the following is a valid statement to accept int input? Let us assume that we have
declared scan as Scanner.

Select one:
a. int num = scan.getInt();
b. short num = scan.nextShort();
c. int num = scan.nextInt();

d. int num = scan.nextLong();


Feedback

Your answer is incorrect.

Question 38
Correct
Mark 2.00 out of 2.00

Flag question

Question text

What is the extension name of a Java Source code?

Select one:
a. javac
b. j
c. java 
d. class
e. None of the choices

Question 39
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

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

Select one:
a. 1
b. 3
c. 4 

d. 2
Feedback

Your answer is incorrect.

Question 40
Incorrect
Mark 0.00 out of 1.00

Flag question

Question text

It is used to access the instance variables shadowed by the parameters.

Select one:
a. this
b. accessor method 
c. mutator method
d. method

Question 41
Correct
Mark 2.00 out of 2.00

Flag question

Question text

What is the maximum index of the array:


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

Select one:
a. 7
b. 4
c. 5 

d. 6
Feedback

Your answer is correct.

Question 42
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is a valid multidimensional array?

Select one:
a. int[][][][] intArray;
b. All of the choice 
c. int[][] intArray;
d. int intArray[][][];

e. int[][][] intArray;
Feedback

Your answer is correct.

Question 43
Correct
Mark 1.00 out of 1.00

Flag question

Question text

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

Select one:
a. javac HelloWorld
b. java HelloWorld.java
c. java HelloWorld 

d. javac HelloWorld.java
Feedback

Your answer is correct.

Question 44
Correct
Mark 1.00 out of 1.00

Flag question

Question text

Which of the following is a valid identifier?


Select one:
a. public
b. true
c. static
d. name 
e. None of the choices

Question 45
Correct
Mark 1.00 out of 1.00

Flag question

Question text

What was the initial name of the Java programming language?

Select one:
a. Oak 
b. C
c. None of the choices
d. Javad
e. NetBeans

You might also like