Modulo 1 - Chapter 1 - Questions
Modulo 1 - Chapter 1 - Questions
Modulo 1 - Chapter 1 - Questions
Question 1
Given:
class EJava {
//..code
}
b.
package java.oca;
import EJava;
class Guru {
EJava eJava;
}
c.
package java.oca.*;
import java.default.*;
class Guru {
EJava eJava;
}
d.
package java.oca.associate;
import default.*;
class Guru {
default.EJava eJava;
}
Question 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
a. 1, 3, 2, 5, 6, 4
b. 3, 1, 2, 5, 4, 6
c. 3, 2, 1, 4, 5, 6
d. 3, 2, 1, 5, 6, 4
Chapter 1
Question 3
Which of the following examples defines a correct Java class structure?
a.
#connect java compiler;
#connect java virtual machine;
class EJavaGuru {}
b.
package java compiler;
import java virtual machine;
class EJavaGuru {}
c.
import javavirtualmachine.*;
package javacompiler;
class EJavaGuru {
void method1() {}
int count;
}
d.
package javacompiler;
import javavirtualmachine.*;
class EJavaGuru {
void method1() {}
int count;
}
e.
#package javacompiler;
$import javavirtualmachine;
class EJavaGuru {
void method1() {}
int count;
}
f.
package javacompiler;
import javavirtualmachine;
Class EJavaGuru {
void method1() {}
int count;
}
Chapter 1
Question 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 {}
Question 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
a. one:two:three
b. EJavaGuru:one:two
c. java:EJavaGuru:one
d. two:three:four
Chapter 1
Question 6
Which of the following options, when inserted at //INSERT CODE HERE, will print
out EJavaGuru?
Question 7
What is the meaning of “write once, run anywhere”? Select the correct options:
a. Java code can be written by one team member and executed by other team
members.
b. It is for marketing purposes only.
c. It enables Java programs to be compiled once and can be executed by any JVM
without recompilation.
d. Old Java code doesn’t need recompilation when newer versions of JVMs are
released.
Chapter 1
Question 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?
a. import mycode.com.ejavaguru.Course;
b. import com.ejavaguru.Course;
c. import mycode.com.ejavaguru;
d. import com.ejavaguru;
e. import mycode.com.ejavaguru*;
f. import com.ejavaguru*;
Chapter 1
Question 9
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?
a. The class EJavaGuru will print Java.
b. The class EJavaGuru will print null.
c. The class EJavaGuru won’t compile.
d. The class EJavaGuru will throw an exception at runtime.
Chapter 1
Question 10
Given the following definition of the class Course,
package com.ejavaguru.courses;
class Course {
public String courseName;
}
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);
}
}
Question 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;
}
}
Question 12
Which of the following statement is true?
Question 13
A Java class will always have _________ .
a. A main method.
b. Variable(s).
c. At least one method.
d. A Constructor.
e. All of the above.
Chapter 1
Question 14
What will be the output of this program?
a. 10
b. No output will be produced.
c. Compilation fails due to error at line 1.
d. Compilation fails due to error at line 8.
e. Compilation fails due to multiple errors.
Chapter 1
Question 15
How many objects are eligible for GC at the execution of //line 14?
a. 0
b. 1
c. 2
d. 3
e. Compilation fails.
Chapter 1
Question 16
What will be the output of this program code?
a. true false
b. false false
c. An Exception is thrown.
d. Compilation fails due to error at line 7.
e. Compilation fails due to error at line 8.
Chapter 1
Question 17
Given the following classes, what is the maximum number of imports that can be
removed and have the code still compile?
package aquarium; public class Water { }
package aquarium;
import java.lang.*;
import java.lang.System;
import aquarium.Water;
import aquarium.*;
public class Tank {
public void print(Water water) {
System.out.println(water); } }
A. 0
B. 1
C. 2
D. 3
E. 4
F. Does not compile.
Chapter 1
Question 18
Given the following class, which of the following is true? (Choose all that apply)
Question 19
Which of the following legally fill in the blank so you can run the main() method
from the command line? (Choose all that apply)
Question 20
Which of the following are true? (Choose all that apply)
public class Bunny {
public static void main(String[] args) {
Bunny bun = new Bunny();
}
}
A. Bunny is a class.
B. bun is a class.
C. main is a class.
D. Bunny is a reference to an object.
E. bun is a reference to an object.
F. main is a reference to an object.
G. None of the above.
Chapter 1
Question 21
Given the following classes, which of the following can independently replace INSERT
IMPORTS HERE to make the code compile? (Choose all that apply)
package aquarium;
public class Tank { }
package aquarium.jellies;
public class Jelly { }
package visitor;
INSERT IMPORTS HERE
public class AquariumVisitor {
public void admire(Jelly jelly) { } }
A. import aquarium.*;
B. import aquarium.*.Jelly;
C. import aquarium.jellies.Jelly;
D. import aquarium.jellies.*;
E. import aquarium.jellies.Jelly.*;
F. None of these can make the code compile.