Anda di halaman 1dari 3

Practice Test No 1. Programming Java Ing.

Matilde Montealegre Madero, MSc March 31/2019


Question 3: Which access modifier makes a member available only to classes within the same package or
subclasses?

A) private B) protected C) public D) package-private

Question 4: Examine the following content of Java source code file Multiple.java and select the correct
options:

// Contents of Multiple.java
public interface Printable {
//.. we are not detailing this part
}
interface Movable {
//.. we are not detailing this part
}

A. A Java source code file can’t define multiple interfaces.

B. A Java source code file can only define multiple classes.

C. A Java source code file can define multiple interfaces and classes.

D. The previous class will fail to compile.

Question 5: Examine the content of the following Java source code file, Multiple2.java, and select the correct
option(s):

// contents of Multiple2.java
interface Printable {
//.. we are not detailing this part
}
class MyClass {
//.. we are not detailing this part
}
interface Movable {
//.. we are not detailing this part
}
public class Car {
//.. we are not detailing this part
}
public interface Multiple2 {}

A. The code fails to compile. B. The code compiles successfully.

C. Removing the definition of class Car will compile the code.

D. Changing class Car to a nonpublic class will compile the code.

E. Changing interface Multiple2 to a nonpublic interface will compile the code.

Question 6: What is the result of the following class? (Choose all that apply)
1: public class _C {
2: private static int $;
3: public static void main(String[] main) {
4: String a_b;
5: System.out.print($);
6: System.out.print(a_b);
7: } }

A. Compiler error on line 1. B. Compiler error on line 2. C. Compiler error on line 4.


D. Compiler error on line 5. E. Compiler error on line 6. F. 0null G. nullnull

Question 7: Bytecode is in a file with which extension?


A .bytecode B .bytes C .class D .exe E .javac F .java

Question 8: The following piece of code doesn’t compile. Fix it to compile it.
public class ImportExample {
public static void main(String[] args) {
Random r = new Random();
System.out.println(r.nextInt(10));
}
}

Question 9: In the following code, how many of the imports do you think are redundant?
1: import java.lang.System;
2: import java.lang.*;
3: import java.util.Random;
4: import java.util.*;
5: public class ImportExample {
6: public static void main(String[] args) {
7: Random r = new Random();
8: System.out.println(r.nextInt(10));
9: }
10: }

Question 10: Choose all the imports that do not work.


A. import java.nio.*; B. import java.nio.file.Files; C. import java.nio.file.Paths;
D. import java.nio.file.*; E. import java.nio.*.*; F. import java.nio.files.Paths.*;

Anda mungkin juga menyukai