Follow and like us on our Facebook page where we post on the new release subject and answering tips and tricks to help save your time so that you can never feel stuck again.
Shortcut

Ctrl + F is the shortcut in your browser or operating system that allows you to find words or questions quickly.

Ctrl + Tab to move to the next tab to the right and Ctrl + Shift + Tab to move to the next tab to the left.

On a phone or tablet, tap the menu icon in the upper-right corner of the window; Select "Find in Page" to search a question.

Share Us

Sharing is Caring

It's the biggest motivation to help us to make the site better by sharing this to your friends or classmates.

Computer Programming 2

A course that builds upon foundational programming concepts, focusing on data structures, and problem-solving techniques to further develop programming skills.

loops

functions

arrays

pointers

recursion

algorithms

data structures

object-oriented programming

inheritance

polymorphism

exception handling

file handling

dynamic memory allocation

debugging

testing.

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

  • 3

The length of an array is established when the array is created at __________.

  • None of the above
  • runtime
  • initialization
  • compile time
  • declaration

What is the input for Java Compiler?

  • Code
  • Byte Code
  • Native Code
  • Source Code
  • None of the Above

Which of the following is not the feature of java?

  • Static

Can we directly compile codes from NetBeans?

  • It depends, if there is a compiler embedded in NetBeans
  • No, we can only write codes in NetBeans
  • Yes, because we can call Java compiler from NetBeans
  • Both A and C are correct

Which of the following does not return numeric value?

  • None of these

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

  • 1010
  • None of the choices
  • 11
  • 10
  • 101

What will happen if you use JOptionPane.showMessageDialog statement in your program?

  • The program will display an input dialog box that allows the user to input text and returns String value
  • The program will display message dialog box
  • None of the above
  • The program will display message dialog box returns String value
  • The program will display an input dialog box that allows the user to input text and returns the correct type value

what will be the output if you execute this code?int x=1;switch(x){case 1: System.out.print(=E2=80=9C1=E2=80=9D);case 2: System.out.print(=E2=80=9C1=E2=80=9D);case 3: System.out.print(=E2=80=9C1=E2=80=9D);default: System.out.print(=E2=80=9C1=E2=80=9D);}

  • None of the above}
  • display 1234
  • display nothing
  • display 1111
  • display 1

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

  • None of the above
  • Do nothing
  • The code will not run because of syntax error
  • print "Hello World"
  • print "Hello World" infinitely

Which of the following shows a valid Overloading method?

  • none of the choices
  • void test(int x){} void test(int y){}
  • All of the choices
  • void test(char x, int y){} void test(int x, char y){}
  • void test(){} void test(){}

What type of value does the nextLine() returns?

  • None of the above
  • Line
  • double
  • String
  • long

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

  • Multithreaded

True or False. Please select the best answer for the question.Portable is one of Java's control structures

  • True
  • False

Which of the following method is allowed to be overriden?

  • public final void setName(){}

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

  • print "Hello World" infinitely

What do you call a class that inherits a class?

  • Parent class
  • Class
  • Superclass
  • Subclass
  • None of the above

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

  • true

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

  • 765321

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

  • public class Person use [InterfaceName] {}
  • public class Person extends [InterfaceName] {}
  • public class Person implements [InterfaceName] {}
  • None of the above
  • public class Person apply [InterfaceName] {}

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

  • public interface [InterfaceName] {}
  • public [InterfaceName] {}
  • interface: [InterfaceName]
  • public class interface [InterfaceName] {}

True or False. Please select the best answer for the question.Repetition is one of Java's control structures

  • True
  • False

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

  • test()
  • 1
  • None of the above
  • void
  • int

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

  • 1010
  • long value
  • floating-point literal
  • None of the above
  • 31416

True or False. Please select the best answer for the question.byte, short, int, and for are one of Java's Primitive data types.

  • True
  • False

Which of the following declares an array of int named intArray?

  • All of these

Which of the following is the correct way to call the constructor of the parent class?

  • thiscall()
  • super()
  • supercall()
  • this()

What was the initial name for the Java programming language?

  • Oak

Multiple-Choice. Please select the best answer for the question.Which statement will check if x is less than y?

  • if (x>y)?:
  • if (x<=y)
  • if (x<y);
  • none of the above
  • if (x>y)

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

  • display 111

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

  • None of the above
  • Class Variable
  • Class Method
  • Static Variable
  • Object Variable

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

  • package ;

Which of the following is true about constructor?

  • All of the choices

It used to read values from class variables?

  • Accessor

Which of the following creates an instance of a class?

  • Test t = new Test();
  • All of the choices
  • String str = new String();
  • Object obj = new Object();

What will be the output if you execute this code? do{System.out.println(&quot;Hello World!&quot;);}while(false);

  • print &quot;Hello World&quot;

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

  • int 25
  • String 25
  • The code is not valid
  • 0
  • None of the above

Which of the following is not Java Literal?

  • Character value
  • Boolean value
  • None of the above
  • Integer value
  • Float value

What will be the value of x after you execute this statement int z=0; for(int x=0; x

  • None of these

What will be the value of x after you execute this statementint z=0; for(int x=0; x<10; x++) for(int y=0; y<x; y++) z*=(x*y);

  • 128
  • None of the above
  • 236
  • 512
  • 1

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

  • 31416
  • double value
  • floating-point literal
  • 120
  • All of the above

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

  • All of the choices

Why do we need to set the path for javac in command line?

  • To resolve runtime error
  • It is part of the compilation process
  • None of the Above
  • To make javac available or accessible in command line
  • To resolve syntax error

Declare and initialize a double data type array named numbers with the following values: 23.35, 34.45, 56.77.

  • double[ ] numbers={2335, 3445, 5677};
  • double[ ] numbers={&quot;2335, 3445, 5677&quot;};
  • None of the choices
  • double[3] numbers={2335, 3445, 5677};
  • Double[ ] number={2335, 3445, 5677};

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

  • Encapsulation
  • Class
  • Object
  • None of the above
  • Object Oriented

True or False. Please select the best answer for the question.for, while and do-while is part of Java's Repetition Control Structures

  • True
  • False

What is the output of the code snippet below: int[] intArray = new int[10]; for(int x = 0; x <intArray.length; x++) {System.out.print(intArray[x]);}

  • 0000000000

True or False. Please select the best answer for the question.Java is architecture neutral

  • True
  • False

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

  • 11

Which of the following scenarios where an exception may occur?

  • All of the choices

True or False. Please select the best answer for the question.Java SE is a Java Platform

  • True
  • False

Use the __________ statement when traversing through arrays.

  • whilewhile loop
  • switch
  • do-while loop
  • for loop
  • none of the choices

What keyword is used to perform class inheritance?

  • extends
  • derives
  • inherits
  • implements
  • None of the above

Can we directly compile codes from notepad?

  • Yes, Because we can call Java compiler from notepad
  • It depends, if there is a compiler embedded in Notepad
  • Both A and C are correct
  • No, We can only write codes in Notepad

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

  • None of the Above
  • java HelloWorld
  • javac HelloWorldjava
  • java HelloWorldjava
  • javac HelloWorld

What is the output of the code snippet below: void main(){test(=E2=80=9C11=E2=80=9D);test(=E2=80=9C1=E2=80=9D);} void test(String x){System.out.print(x + x);}

  • 222
  • 111111
  • 6
  • None of the choices

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

  • 29

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

  • true

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

  • 3
  • short value
  • None of the above
  • 128
  • int value

Which of the following is not a java keyword?

  • goto
  • else
  • if
  • None of the above
  • name

Which of the following shows Overloading method?

  • void test(int x){} void test(double x){}
  • None of the above
  • void test(){} void test(){}
  • All of the above
  • void test(int x){} void test(int y){}

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

  • int num = scannextLong();
  • short num = scannextInt();
  • short num = scannextShort();
  • int num = scangetInt();
  • None of the above

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

  • public abstract class Person {}
  • None of the above
  • public class Person {}
  • class Person{}
  • public final class Person {}

Which of the following methods is allowed to be overriden?

  • public no_override void setName(){}
  • public void setName(){}
  • public final void setName(){}
  • public static void setName(){}
  • None of the above

Which of the following is not a valid Float value?

  • 12345678910F
  • 123
  • 12345E+3
  • none of the above
  • 34028235E+38F

True or False. Please select the best answer for the question.Java's control structures are branching, decision, and multithreaded.

  • True
  • False

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

  • None of the Choice

Which of the following is a valid method name:

  • compute
  • final
  • int
  • compute grade
  • none of the choices

True or False. Please select the best answer for the question.Java is a simple, object-oriented, portable and robust computer language.

  • True
  • False

Multiple-Choice. Please select the best answer for the question.Which of the following a valid Java identifier?

  • $id
  • id
  • id_1
  • all of the above
  • _id

What will happen if we compile the statement below? ~System.out.println(“Hello World!”)

  • There will be a syntax error after compilation.

True or False. Please select the best answer for the question.Java is secured

  • True
  • False

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

  • 5

What is the output of the code snippet below: void main(){test();test();} void test(){System.out.print(=E2=80=9C1=E2=80=9D);}

  • 2
  • 11
  • 3
  • 1
  • None of the choices

Which of the following a valid Java identifier?

  • all of the above
  • id
  • id_1
  • $id
  • _id

Which of the following is true about syntax errors:

  • Incorrect capitalization leads to syntax error
  • Syntax errors are usually typing errors
  • All of the above
  • You will have syntax errors if you misspell the Java command
  • None of the Above

Multiple-Choice. Please select the best answer for the question.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);?

  • 236
  • 128
  • 512
  • None of the above
  • 1

Which of the following is not a Java comment?

  • None of the above
  • Multi-Line Comments
  • Single Line Comments
  • Declaration Comments
  • Documentation Comments

Which of the following will do implicit cast?

  • None of the above
  • String x = =E2=80=9C0=E2=80=9D; int y = x;
  • All of the above
  • short x=1; int y = x;
  • Object obj = new Object();

Which of the following is not a primitive data type?

  • byte
  • short
  • none of the above
  • long
  • String

What is the output of the code snippet below: void main(){test(“11”);test(“1”);} void test(String x){System.out.print(x + x);}

  • 111111

Which of the following is a correct declaration of an array?

  • Double[ ] dbl= new Double(5);
  • StudentRecord sr=new StudentRecord[100];
  • PaySlip[ ] ps=new ps;
  • None of the choices
  • EmployeeRecord[ ][ ] er=new EmployeeRecord[10][10];

Which statement will check if x is less than y?

  • if (x<y);
  • if (x>y)
  • if (x>y)?:
  • none of the above
  • if (x<>y)

What will happen if you use JOptionPane. showInputDialog statement in your program?

  • The program will display an input dialog box that allows the user to input text and returns String value
  • The program will display message dialog box
  • None of the above
  • The program will display message dialog box returns String value
  • The program will display an input dialog box that allows the user to input text and returns the correct type value

When was the officially released of Java?

  • 1991
  • None of the Above
  • 1995
  • 1992
  • 1996

What is the correct statement to set javac path in command line?

  • None of the Above
  • set path=C:Program FilesJava
  • All of the above
  • javac
  • set path
  • C:Program FilesJavajdk160_23bin
  • path=C:Program FilesJavajdk160_23bin

What did java generates after compiling the java source code?

  • Byte Code

Multiple-Choice. Please select the best answer for the question.Which is not a repetition control structure?

  • loop
  • None of the above
  • do-while
  • for
  • while

Which of the following is a jump statement in java?

  • break
  • jump
  • continue
  • else
  • default

__________ is implemented in at least two classes with inheritance relationship.

  • Inheritance
  • None of the options
  • Overriding
  • Polymorphism
  • Overloading

The __________ keyword allocates memory for the array being declared.

  • new
  • array
  • int
  • intArray
  • None of the above

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

  • test
  • All of the choices
  • int
  • return 1
  • 1

What will happen if we compile the statement below?~System.out.println(=E2=80=9CHello World!=E2=80=9D)

  • There will be a syntax error after compilation
  • There will be a logical error after compilation
  • There will be a runtime error after compilation
  • None of the Above
  • There will be no error after compilation

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

  • 765321
  • 12356
  • 123567
  • The given code is not valid
  • none of the choices

What is the output of the code snippet below: void main(){test();test();} void test(){System.out.print(“1”);}

  • 11

Which of the following is not a valid variable declaration in Java?

  • int x = 1;
  • int x;
  • float x = 20D;
  • short x;
  • None of the above

What is the return value of this method: public void sum(){int x=1;} ?

  • 1
  • sum
  • none of the choices
  • void
  • x

Which of the following show casting object?

  • (className) object;
  • Employee emp = new Employee(); VicePresident veep = new VicePresident(); veep = (VicePresident)emp;
  • SuperClass sc = new SuperClass(); SubClass sbc = new SubClass(); sbc = (SubClass) sc;
  • All of the choices

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

  • None of the above
  • The code will not run because of syntax error
  • Do nothing
  • print &quot;Hello World&quot; infinitely
  • print &quot;Hello World&quot;

Since Java uses a virtual machine, what does that mean about the versatility of Java?

  • None of the Above
  • It can run most anywhere without modification
  • Code Security
  • It is used almost exclusively on Intel platforms
  • It will run on Windows, Linux, Unix, but not Apple

What is the output of the code snippet below: int[] intArray = new int[10];for(int x = 0; x<intArray.length; x++){System.out.print(intArray[x]);}

  • 0000000000
  • 012356789
  • The given code is not valid
  • 1235678910
  • none of the choices

The Java feature, &quot;write once, run anywhere&quot;, is termed as

  • Object Oriented
  • None of the Above
  • Platform independent
  • High Performance
  • Robust

What is the extension name of a Java Source code?

  • j
  • None of the Above
  • java
  • class
  • javac

Multiple-Choice. Please select the best answer for the question.Which of the following has the correct form for an if statement?

  • none of the above
  • if boolean_expression
  • if { boolean_expression }
  • boolean_expression
  • if (boolean_expression)

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

  • 19

What is the result if we execute this: =E2=80=9Ca=E2=80=9D.equals(=E2=80=9Ca=E2=80=9D);?

  • false
  • =E2=80=9Ca=E2=80=9D
  • true
  • None of the above
  • The code is not valid

what will be the output if you execute this code? int x=1; 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”); }

  • display 1111

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

  • 1.01

How many elements could be assigned to an array location with 5 columns and 3 rows?

  • 5
  • 15
  • 8
  • 3
  • None of the choices

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

  • none of the above
  • 11
  • 10
  • 1
  • 0

Which is not a decision control structure?

  • if else
  • if
  • if else-if else
  • switch
  • None of the above

Which of the following correctly accesses the sixth element stored in an array of 10 elements?

  • stringArray[5];

Which of the following has the correct form for an if statement?

  • if boolean_expression
  • boolean_expression
  • if (boolean_expression)
  • none of the above

JVM is responsible for

  • Generating bytecode
  • None of the Above
  • Compiling source code
  • Interpreting bytecode
  • Reading bytecode

Which of the following is a valid multidimensional array?

  • All of these

Which of the following is a valid statement to accept String input?

  • String num = scannextText();
  • None of the above
  • string str = scannextShort();
  • String str = JOptionPaneshowInputDialog(&quot;&quot;);
  • String str = scannextString();

True or False. Please select the best answer for the question.float is one of Java's Primitive data types

  • True
  • False

What will be the output if you execute this code: int a[] = new int[1]; System.out.println(a[1]);

  • It will produce an exception.

What do you call a blueprint of an object?

  • Object
  • None of the above
  • Class
  • Constructor
  • Method

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

  • 12

What is the result if we execute this: =E2=80=9Ca=E2=80=9D instanceof String; ?

  • The code is not valid
  • false
  • true
  • =E2=80=9Ca=E2=80=9D
  • None of the above

Which of the following array declarations is correct?

  • double[ ] grades;grades = new double[2];
  • double[10] money=double[ ];
  • byte[ ] b=byte[ 20];
  • Integer i[ ]=new Integer;
  • String names[20]=new String;

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

  • public abstract class Person {}
  • class Person{}
  • public class Person {}
  • None of the above
  • public final class Person {}

It is a template for creating an object?

  • None of the above
  • Object Oriented
  • Method
  • Class
  • Encapsulation

Multiple-Choice. Please select the best answer for the question.Which of the following is not a primitive data type?

  • none of the above
  • int
  • byte
  • String
  • double

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

  • 7
  • None of the choices
  • int
  • 6
  • test

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

  • javac HelloWorld
  • java HelloWorldjava
  • javac HelloWorldjava
  • java HelloWorld

Multiple-Choice. Please select the best answer for the question.Which is not a decision control structure?

  • switch
  • if else-if else
  • if else
  • None of the above
  • if

Which statement will check if x is equal to y?

  • if (x>y)
  • if (x<>y)
  • none of the above
  • if (y>y)
  • if (x!<y)

Which of the following is not an escape sequence?

  • t
  • b
  • none of the above
  • f

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

  • this

Which of the following is true about Runtime errors:

  • Runtime errors occur after compilation
  • Runtime errors occur during run-time
  • Runtime errors occur when there is a design flaw in your program
  • All of the above
  • None of the Above

Which of the following is a valid identifier?

  • true
  • static
  • name
  • None of the above
  • public

Declare a two-dimensional integer array named values of size 6 columns and 4 rows.

  • int[ ][ ] values=new int[4][6];
  • int[ 6][4 ] values=new int;
  • int values=new int[6][4];
  • int[ ][ ] values=new int[6][4];
  • None of the above

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

  • 6

Which of the following is true about Interface?

  • All of the above
  • It defines a standard and public way of specifying the behavior of classes
  • It is use to model multiple inheritance which allows a class to have more than one superclass
  • It is a special kind of block containing method signatures only
  • It defines the signatures of a set of methods without the body

What is floating-point literal?

  • Can be express in scientific notation
  • All of the above
  • An integer literal with decimal point
  • By default it is double type
  • It could be double or float value

What does Java generate after compiling the java source code?

  • Class Code
  • Image file
  • Executable file
  • None of the Above
  • Byte Code

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

  • 5

Which is not a repetition control structure?

  • None of the choices
  • switch
  • do while
  • for
  • while

Multiple-Choice. Please select the best answer for the question. What will be the result if you execute this expression x=true ? 1 : 0;?

  • 1
  • 0
  • false
  • true
  • none of the above

Which of the following method reads input from the user and return String value?

  • nextLine()
  • nextString()
  • All of the above
  • nextText()
  • nextValue()

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

  • Abstraction
  • Polymorphism
  • Inheritance
  • Interface
  • None of the above

Which of the following we are not allowed to write java source code?

  • Notepad
  • eclipse
  • BlueJ
  • None of the Above
  • NetBeans

Multiple-Choice. Please select the best answer for the question.Which of the following is not a Java Literal?

  • Boolean value
  • Integer value
  • None of the above
  • Float value
  • Character value
Comments