1.9. Sample exam questions

Q1-1.

Given:

class EJava {
    //..code
}

Which of the following options will compile?


  1. package java.oca.associate;
    class Guru {
        EJava eJava = new EJava();
    }

  2. package java.oca;
    import EJava;
    class Guru {
        EJava eJava;
    }

  3. package java.oca.*;
    import java.default.*;
    class Guru {
        EJava eJava;
    }

  4. package java.oca.associate;
    import default.*;
    class Guru {
        default.EJava eJava;
    }
  5. None of the above

Q1-2.

The following numbered list of Java class components is not in any particular order. Select the acceptable order of their occurrence in any Java class (choose all that apply):

  1. comments
  2. import statement
  3. package statement
  4. methods
  5. class declaration
  6. variables

  1. 1, 3, 2, 5, 6, 4
  2. 3, 1, 2, 5, 4, 6
  3. 3, 2, 1, 4, 5, 6
  4. 3, 2, 1, 5, 6, 4

Q1-3.

Which of the following examples defines a correct Java class structure?


  1. #connect java compiler;
    #connect java virtual machine;
    class EJavaGuru {}

  2. package java compiler;
    import java virtual machine;
    class EJavaGuru {}

  3. import javavirtualmachine.*;
    package javacompiler;
    class EJavaGuru {
        void method1() {}
        int count;
    }

  4. package javacompiler;
    import javavirtualmachine.*;
    class EJavaGuru {
        void method1() {}
        int count;
    }

  5. #package javacompiler;
    $import javavirtualmachine;
    class EJavaGuru {
        void method1() {}
        int count;
    }

  6. package javacompiler;
    import javavirtualmachine;
    Class EJavaGuru {
        void method1() {}
        int count;
    }

Q1-4.

Given the following contents of the Java source code file MyClass.java, select the correct options:

// contents of MyClass.java
package com.ejavaguru;
import java.util.Date;
class Student {}
class Course {}

  1. The imported class, java.util.Date, can be accessed only in the class Student.
  2. The imported class, java.util.Date, can be accessed by both the Student and Course classes.
  3. Both of the classes Student and Course are defined in the package com.ejava-guru.
  4. Only the class Student is defined in the package com.ejavaguru. The class Course is defined in the default Java package.

Q1-5.

Given the following definition of the class EJavaGuru,

class EJavaGuru {
    public static void main(String[] args) {
        System.out.println(args[1]+":"+ args[2]+":"+ args[3]);
    }
}

what is the output of EJavaGuru, if it is executed using the following command?

java EJavaGuru one two three four

  1. one:two:three
  2. EJavaGuru:one:two
  3. java:EJavaGuru:one
  4. two:three:four

Q1-6.

Which of the following options, when inserted at //INSERT CODE HERE, will print out EJavaGuru?

public class EJavaGuru {
    // INSERT CODE HERE
    {
        System.out.println("EJavaGuru");
    }
}

  1. public void main (String[] args)
  2. public void main(String args[])
  3. static public void main (String[] array)
  4. public static void main (String args)
  5. static public main (String args[])

Q1-7.

What is the meaning of “write once, run anywhere”? Select the correct options:

  1. Java code can be written by one team member and executed by other team members.
  2. It is for marketing purposes only.
  3. It enables Java programs to be compiled once and can be executed by any JVM without recompilation.
  4. Old Java code doesn’t need recompilation when newer versions of JVMs are released.

Q1-8.

A class Course is defined in a package com.ejavaguru. Given that the physical location of the corresponding class file is /mycode/com/ejavaguru/Course.class and execution takes place within the mycode directory, which of the following lines of code, when inserted at // INSERT CODE HERE, will import the Course class into the class MyCourse?

// INSERT CODE HERE
class MyCourse {
    Course c;
}

  1. import mycode.com.ejavaguru.Course;
  2. import com.ejavaguru.Course;
  3. import mycode.com.ejavaguru;
  4. import com.ejavaguru;
  5. import mycode.com.ejavaguru*;
  6. import com.ejavaguru*;

Q1-9.

Examine the following code:

class Course {
    String courseName;
}
class EJavaGuru {
    public static void main(String args[]) {
        Course c = new Course();
        c.courseName = "Java";
        System.out.println(c.courseName);
    }
}

Which of the following statements will be true if the variable courseName is defined as a private variable?

  1. The class EJavaGuru will print Java.
  2. The class EJavaGuru will print null.
  3. The class EJavaGuru won’t compile.
  4. The class EJavaGuru will throw an exception at runtime.

Q1-10.

Given the following definition of the class Course,

package com.ejavaguru.courses;
class Course {
    public String courseName;
}

what’s the output of the following code?

package com.ejavaguru;
import com.ejavaguru.courses.Course;
class EJavaGuru {
    public static void main(String args[]) {
        Course c = new Course();
        c.courseName = "Java";
        System.out.println(c.courseName);
    }
}

  1. The class EJavaGuru will print Java.
  2. The class EJavaGuru will print null.
  3. The class EJavaGuru won’t compile.
  4. The class EJavaGuru will throw an exception at runtime.

Q1-11.

Given the following code, select the correct options:

package com.ejavaguru.courses;
class Course {
    public String courseName;
    public void setCourseName(private String name) {
        courseName = name;
    }
}

  1. You can’t define a method argument as a private variable.
  2. A method argument should be defined with either public or default accessibility.
  3. For overridden methods, method arguments should be defined with protected accessibility.
  4. None of the above.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.182.66