Kerri  Chinneck
Quiz by , created more than 1 year ago

National Senior Certificate (Matric) Information Technology Quiz on OCA, created by Kerri Chinneck on 03/18/2017.

12
2
0
Kerri  Chinneck
Created by Kerri Chinneck almost 4 years ago
Close
  • OCA

    Question 1 of 10

    1

    What happens when the following program is compiled and run?

    public class MyData {

    String name;
    int i;
    int i2 = 4;
    int i3 = i2 / i;

    public static void main(String[] args){
    MyData md = new MyData();
    System.out.print(md.i3);
    }
    }

    Select one of the following:

    • This code writes "0" to the standard output.

    • This code writes nothing to the standard output.

    • This code writes "null" to the standard output.

    • This code writes error dividing by zero to the standard output.

    Explanation

    Question 2 of 10

    1

    What happens when the following program is compiled and run?

    public class Employee {

    // Primitive data types
    double salary;
    int age;
    boolean isPaid;
    char gender = 'm'; // m = male, f = female

    public static void main(String[] args){
    Employee emp = new Employee();
    System.out.print(" " + emp.salary + ",");
    System.out.print(" " + emp.age + ",");
    System.out.print(" " + emp.isPaid + ",");
    System.out.print(" " + emp.gender);
    }
    }

    Select one of the following:

    • This code writes ", , , m" to the standard output.

    • This code writes "1.0, 1, true, m" to the standard output.

    • This code writes "0.0, 0, false, m" to the standard output.

    • This code does not compile, because some of the variables are not initialized.

    Explanation

    Question 3 of 10

    1

    What will be the result of calling the following method with an input of 2?

    1. public int adder( int N ){
    2. return 0x100 + N++ ;
    3. }

    Select one of the following:

    • The method will return 258.

    • The method will return 102.

    • The method will return 259.

    • The method will return 103.

    Explanation

    Question 4 of 10

    1

    What happens when you attempt to compile and run the following code?

    1. public class Logic {
    2. static int minusOne = -1 ;
    3. static public void main(String args[] ){
    4. int N = minusOne >> 31 ;
    5. System.out.println("N = " + N );
    6. }
    7. }

    Select one of the following:

    • The program will compile and run, producing the output "N = -1".

    • The program will compile and run, producing the output "N = 1".

    • A runtime ArithmeticException will be thrown.

    • The program will compile and run, producing the output "N = 0".

    Explanation

    Question 5 of 10

    1

    How many String objects are created in the following code?

    1. String A, B, C ;
    2. A = new String( "1234" ) ;
    3. B = A ;
    4. C = A + B ;

    Select one of the following:

    • One

    • Two

    • Three

    • Four

    Explanation

    Question 6 of 10

    1

    Which of the following versions of initializing a char variable would cause a compiler error? [Check all correct answers.]

    char c = - 1 ;
    char c = '\u00FF' ;
    char c = (char) 4096 ;
    char c = 4096L ;
    char c = 'c' ;
    char c = "c" ;

    Select one of the following:

    • char c = - 1 ;

    • char c = '\u00FF' ;

    • char c = (char) 4096 ;

    • char c = 4096L ;

    • char c = 'c' ;

    • char c = "c" ;

    Explanation

    Question 7 of 10

    1

    What happens when you try to compile and run the following code?
    1. public class EqualsTest{
    2. public static void main(String args[]){
    3. char A = '\u0005' ;
    4. if( A == 0x0005L ) {
    5. System.out.println("Equal");
    6. }
    7. else {
    8. System.out.println("Not Equal");
    9. }
    10. }
    11. }

    Select one of the following:

    • The compiler reports "Invalid character in input" in line 3.

    • The program compiles and prints "Not Equal".

    • The program compiles and prints "Equal".

    • The compiler objects to the use of == to compare a char and a long.

    Explanation

    Question 8 of 10

    1

    In the following code fragment, you know that the getParameter call may return a null if there is no parameter named size:

    1. int sz ;
    2. public void init(){
    3. sz = 10 ;
    4. String tmp = getParameter("size");
    5. if( tmp != null X tmp.equals("BIG"))
    sz = 20 ;
    6. }

    Select one of the following:

    • &

    • &&

    • |

    • ||

    Explanation

    Question 9 of 10

    1

    What would happen if you tried to compile and run the following code?
    1. public class EqualsTest{
    2. public static void main(String args[]){
    3. Long L = new Long( 7 );
    4. if( L.equals( 7L ))
    System.out.println("Equal");
    5. else System.out.println("Not Equal");
    6. }
    7. }

    Select one of the following:

    • The program would compile and print "Equal".

    • The program would compile and print "Not Equal".

    • The compiler would object to line 4.

    • A runtime cast error would occur at line 4.

    Explanation

    Question 10 of 10

    1

    What would happen if you tried to compile and run the following code?
    1. public class EqualsTest{
    2. public static void main(String args[]){
    3. Object A = new Long( 7 );
    4. Long L = new Long( 7 ) ;
    5. if( A.equals( L ))
    System.out.println("Equal");
    6. else System.out.println("Not Equal");
    7. }
    8. }

    Select one of the following:

    • The program would compile and print "Equal".

    • The program would compile and print "Not Equal".

    • The compiler would object to line 5.

    • A runtime cast error would occur at line 5.

    Explanation