Your browser does not support JavaScript!

Computer Programming 2

Showing 76-146 of 146 answers

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. Correct
What will be the output if you execute this code? do{System.out.println("Hello World!");}while(false);
  • print "Hello World" Correct
What will be the output if you execute this code? do{System.out.println("Hello World!");}while(true);
  • print "Hello World" infinitely Correct
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 Correct
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 Correct
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" Correct
  • print "Hello World" infinitely
What will be the output if you execute this code?do{System.out.println("Hello World!");}while(true); 
  • None of the above
  • The code will not run because of syntax error
  • Do nothing
  • print "Hello World" infinitely Correct
  • print "Hello World"
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");} 
  • None of the above}
  • display 1234
  • display nothing
  • display 1111 Correct
  • display 1
What will be the value of x after executing this code for(int x=0; x<=10; x++) {} is run?
  • 11 Correct
What will be the value of x after executing this code for(int x=0; x<=11; x++) {} is run?
  • 12 Correct
What will be the value of x after executing this codefor(int x=0; x<=10; x++) {} is run? 
  • none of the above
  • 11 Correct
  • 10
  • 1
  • 0
What will be the value of x after you execute this statement int z=0; for(int x=0; x
  • None of these Correct
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 Correct
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 Correct
  • 236
  • 512
  • 1
What will be the value of x if we execute this: String s = "25"; int x = Integer.parseInt(s); ?
  • int 25 Correct
  • String 25
  • The code is not valid
  • 0
  • None of the above
What will happen if we compile the statement below? ~System.out.println(“Hello World!”)
  • There will be a syntax error after compilation. Correct
What will happen if we compile the statement below?~System.out.println("Hello World!")
  • There will be a syntax error after compilation Correct
  • 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 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 Correct
  • 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 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 Correct
  • 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 Correct
  • 1992
  • 1996
Which is not a decision control structure?
  • if else
  • if
  • if else-if else
  • switch
  • None of the above Correct
Which is not a repetition control structure?
  • None of the choices
  • switch Correct
  • do while
  • for
  • while
Which of the following a valid Java identifier?
  • all of the above Correct
  • id
  • id_1
  • $id
  • _id
Which of the following array declarations is correct?
  • double[ ] grades;grades = new double[2]; Correct
  • 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 inherited?
  • public abstract class Person {}
  • None of the above
  • public class Person {}
  • class Person{}
  • public final class Person {} Correct
Which of the following class declaration is not allowed to be instantiated?
  • public abstract class Person {} Correct
  • class Person{}
  • public class Person {}
  • None of the above
  • public final class Person {}
Which of the following correctly accesses the sixth element stored in an array of 10 elements?
  • stringArray[5]; Correct
Which of the following creates an instance of a class?
  • Test t = new Test();
  • All of the choices Correct
  • String str = new String();
  • String str = new String();
  • Object obj = new Object();
Which of the following declares an array of int named intArray?
  • All of these Correct
Which of the following does not return numeric value?
  • None of these Correct
Which of the following has the correct form for an if statement?
  • if boolean_expression
  • boolean_expression
  • if (boolean_expression) Correct
  • none of the above
  • if boolean_expression
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]; Correct
Which of the following is a jump statement in java?
  • break Correct
  • jump
  • continue
  • else
  • default
Which of the following is a valid editor for java source code?
  • All of the choices Correct
Which of the following is a valid identifier?
  • true
  • static
  • name Correct
  • None of the above
  • public
Which of the following is a valid method name:
  • compute Correct
  • final
  • int
  • compute grade
  • none of the choices
Which of the following is a valid multidimensional array?
  • All of these Correct
Which of the following is a valid nexDouble() return value?
  • 31416
  • double value
  • floating-point literal
  • 120
  • All of the above Correct
Which of the following is a valid nextByte() return value?
  • 3 Correct
  • short value
  • None of the above
  • 128
  • int value
Which of the following is a valid nextInt() return value?
  • 1010 Correct
  • long value
  • floating-point literal
  • None of the above
  • 31416
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 Correct
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(""); Correct
  • String str = scannextString();
Which of the following is not a Java comment?
  • None of the above
  • Multi-Line Comments
  • Single Line Comments
  • Declaration Comments Correct
  • Documentation Comments
Which of the following is not a java keyword?
  • goto
  • else
  • if
  • None of the above
  • name Correct
Which of the following is not a primitive data type?
  • byte
  • short
  • none of the above
  • long
  • String Correct
Which of the following is not a valid Float value?
  • 12345678910F
  • 123
  • 12345E+3
  • none of the above Correct
  • 34028235E+38F
Which of the following is not a valid variable declaration in Java?
  • int x = 1;
  • int x;
  • float x = 20D; Correct
  • short x;
  • None of the above
Which of the following is not an escape sequence?
  • \t
  • \b
  • none of the above Correct
  • \f
Which of the following is not Java Literal?
  • Character value
  • Boolean value
  • None of the above Correct
  • Integer value
  • Float value
Which of the following is not the feature of java?
  • Static Correct
Which of the following is the correct syntax to define a method?
  • package ; Correct
Which of the following is the correct way to call the constructor of the parent class?
  • thiscall()
  • super() Correct
  • supercall()
  • this()
Which of the following is the correct way to define an interface?
  • public interface [InterfaceName] {} Correct
  • public [InterfaceName] {}
  • interface: [InterfaceName]
  • public class interface [InterfaceName] {}
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] {} Correct
  • None of the above
  • public class Person apply [InterfaceName] {}
Which of the following is true about constructor?
  • All of the choices Correct
Which of the following is true about Interface?
  • All of the above Correct
  • 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
Which of the following is true about Runtime errors:
  • Runtime errors occur after compilation
  • Runtime errors occur during run-time Correct
  • 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 true about syntax errors:
  • Incorrect capitalization leads to syntax error
  • Syntax errors are usually typing errors
  • All of the above Correct
  • You will have syntax errors if you misspell the Java command
  • None of the Above
Which of the following method is allowed to be overriden?
  • public final void setName(){} Correct
Which of the following method reads input from the user and return String value?
  • nextLine() Correct
  • nextString()
  • All of the above
  • nextText()
  • nextValue()
Which of the following methods is allowed to be overriden?
  • public no_override void setName(){}
  • public void setName(){} Correct
  • public final void setName(){}
  • public static void setName(){}
  • None of the above
Which of the following scenarios where an exception may occur?
  • All of the choices Correct
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 Correct
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){} Correct
  • void test(){} void test(){}
Which of the following shows Overloading method?
  • void test(int x){} void test(double x){} Correct
  • None of the above
  • void test(){} void test(){}
  • All of the above
  • void test(int x){} void test(int y){}
Which of the following we are not allowed to write java source code?
  • Notepad
  • eclipse
  • BlueJ
  • None of the Above Correct
  • NetBeans
Which of the following we are not allowed to write java source code?
  • eclipse
  • None of the Above Correct
  • NetBeans
  • BlueJ
  • Notepad
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; Correct
  • Object obj = new Object();
Which statement will check if x is equal to y? 
  • if (x>y)
  • if (x<>y)
  • none of the above Correct
  • if (y>y)
  • if (x!<y)
Which statement will check if x is less than y? 
  • if (x<y); Correct
  • if (x>y)
  • if (x>y)?:
  • none of the above
  • if (x<>y)
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 Correct
  • To resolve syntax error
All courses