Quiz : OCA Java SE 8 Certification : Java basics Quiz

OCA Java SE 8 Certification : Java basics Quiz
Total Question : 11

OCA Java SE 8 Certification Java basics level is a test online cover the structure of a Java class, with its components: package and import statements, class declara-tions, comments, variables, and methods. Difference between the components of a Java class and that of a Java source code file.

  1. Given:

    class EJava { //..code}

    Which of the following options will compile

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

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

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

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

    // contents of MyClass.javapackage com.ejavaguru;
    import java.util.Date;
    class Student {}
    class Course {}
  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 the previous class, if it is executed using the following command?

    java EJavaGuru one two three four
  6. Which of the following options, when inserted at //INSERT CODE HERE, will printout EJavaGuru?

    public class EJavaGuru {
        // INSERT CODE HERE     {
               System.out.println("EJavaGuru");
        }
    }
  7. What is the meaning of “write once, run anywhere”?

    Select the correct options:

  8. A class Course is defined in a package com.ejavaguru. Given that the physicallocation  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;
    }
  9. Examine the following code:

    class Course { 
       private 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 asa private variable?

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

     


Retated posts