Presentation is loading. Please wait.

Presentation is loading. Please wait.

1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.

Similar presentations


Presentation on theme: "1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual."— Presentation transcript:

1 1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual Machine; B.Java Verified Machine; C.Java Voice Machine; D.Java Void Machine ; E.none of the above. 3.Which one of the following statements is true? A.Java is the only object-oriented programming language; B.Java programs can be run only on a PC - not an Apple Mac; C.Java is one of many object-oriented programming languages; D.Java does not allow you to write object-oriented programs; E. none of the above.

2 4.Which of the following is NOT a primitive Java data type? A.char; B.boolean; C.double; D.String; E.int. 5.Consider the following Java program and then choose the correct statement from the list that follows: public class Q5 { public static void main(String[] args) { System.out.print("Apple ") System.out.print("Lemon") } A.this program contains more than one syntax error; B.this program contains one and only one syntax error; C.this program compiles successfully and produces the following output: Apple Lemon D.this program compiles successfully and produces the following output: Apple Lemon E.none of the above.

3 6.Consider the following Java program and then choose the correct statement from the list that follows: public class Q6 { public static void main(String[] args) { System.out.print("I love programming in "); System.out.println("Java"); } A.this program contains more than one syntax error; B.this program contains one and only one syntax error; C.this program compiles successfully and produces the following output: I love programming inJava D.this program compiles successfully and produces the following output: I love programming in Java E.this program compiles successfully and produces the following output: I love programming in Java

4 7.Consider the following Java instruction that declares a variable to store the total number of students taking an exam: int student_total; Which one of the following statements is true? A.this variable declaration is not valid Java syntax ; B.the type int can be used only to store numbers greater than zero ; C.it would have been better to use the type double here; D.using the type double here instead of int would cause a compiler error; E.none of the above.

5 8.Consider the following Java program and then choose the correct statement from the list that follows: public class AnyProg { public static void main (String[] args) { int x, y; x = 5; x++; y = x; x = x + 3; System.out.println ("the value of y is " + y); } A. this program compiles successfully and produces the following output: the value of y is 9 B. this program contains at least one syntax error ; C. this program compiles successfully and produces the following output: the value of y is 6 D. this program compiles successfully and produces the following output: the value of y is + y E. this program compiles successfully and produces the following output: the value of y is 5

6 9.Consider the following two Java programs and then choose the correct statement from the list that follows: public class Prog1 { public static void main (String[] args) { int num; num = 10; System.out.print(num + " divided by " + num + " = " + (num/num)); } public class Prog2 { public static void main (String[] args) { System.out.print(10 + " divided by " " = " + (10/10)); }

7 A.program 1 does not compile but program 2 compiles successfully and produces the following output: 10 divided by 10 = 1 B.both program 1 and program 2 compile successfully and produce the following output: 10 divided by 10 = 1 C.program 2 does not compile but program 1 compiles successfully and produces the following output: 10 divided by 10 = 1 D.neither program compiles successfully; E.both programs compile successfully but produce different output.

8 10.Consider the following program: import java.util.*; public class Q10 { public static void main(String[] args) { int x; Scanner sc = new Scanner(System.in); System.out.print("Enter a number: "); x = sc.nextInt(); if (x > 10) { System.out.println("Liverpool"); } else { System.out.println("Chelsea"); } System.out.println(“Arsenal"); } What would be the output from this program once the user enters 10 when prompted? A.Chelsea Arsenal B.Liverpool Arsenal C.Arsenal D.Chelsea E.none of the above.

9 11.Consider the following program: import java.util.*; public class Q11 { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int choice; System.out.println("enter choice"); choice = sc.nextInt(); switch (choice) { case 1: System.out.println("Gum"); break; case 2: System.out.println("Coke"); default: System.out.println("Error"); } System.out.println("Goodbye"); } If this program is run and the user enters 2 when prompted for a choice, which one of the following statements is true? A.the program displays the following messages before terminating: Gum Goodbye B.the program displays the following messages before terminating: Coke Goodbye C.the program displays the following messages before terminating: Coke Error Goodbye D.the program will crash; E.none of the above.

10 12.Consider the following Java program and then choose the correct statement from the list that follows: public class Q12 { public static void main (String[] args) { for (int i = 1; i < 7; i = i + 2) { System.out.println("*"); } A.this program compiles successfully and produces the following output: ***** B.this program compiles successfully and produces the following output: * * * * C.this program compiles successfully and produces the following output: *** D.this program compiles successfully and produces the following output: * * * E.this none of the above.

11 13.Assume that the user of a program is asked to enter a day number (1-7) into an integer variable called day. Assuming a Scanner object, sc, has been created, which one of the following while loops can then be used to validate the day entered? A.while (day >= 1 || day <= 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt(); } B.while (day >= 1 && day <= 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt (); } C.while (day = 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt (); } D.while (day > 1 && day < 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt (); } E.while (day 7) { System.out.print("ERROR only, enter again: "); day = sc.nextInt (); }

12 14.Consider the following program, and then choose the correct statement from those that follow. public class Q14 { public static void main(String[] args) { int x, result; x = 4; result = 0; result = myMethod(x); System.out.println(result); } private static int myMethod(int numIn) { return 3 * numIn; } A.this program will not compile; B.this program compiles properly and produces the following output: 12 C.this program compiles properly and produces the following output: 0 D.this program compiles properly and produces the following output: 7 E.none of the above.

13 15.Consider the following program, and then choose the correct statement from those that follow. public class Q15 { public static void main(String[ ] args) { int x, y; x = 4; y = 0; y = myMethod( ); System.out.println(y); System.out.println(x); } private static int myMethod(int x) { return 2 * x; } A.this program will not compile; B.this program compiles properly and produces the following output: 8 4 C.this program compiles properly and produces the following output: 0 4 D.this program compiles properly and produces the following output: y x E.none of the above:

14 16.Polymorphism means: A.declaring all the methods of a class as public; B.hiding of information so that it is not accessible to other classes; C.having methods or operators with the same name performing different functions; D.declaring all the attributes of a class as private; E.none of the above. 17.Which of the following statements is true of an array? A.the length of an array can be changed after the array has been created; B.the length of an array can be changed while the program is running; C.an array cannot hold items of mixed type; D.an array cannot be passed to a method; E.none of the above.

15 18.Consider the following explicit creation of an array and then choose the correct statement from the list that follows int[] someArray = { 12, 23, 7, 11, 10, 32 }; A.the value of someArray.length is 5; B.the value of someArray[2] is 23; C.an array cannot be created this way in Java; D.the value of someArray[11] is 4; E.none of the above.

16 19. Consider the following Java program import java.util.*; public class Q19 { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int[ ] mark = new int[5]; for(int i = 0; i <= 5; i++) { System.out.print("Enter mark "); mark[i] = sc.nextInt(); } Which one of the following statements is true of the program above: A.this program will crash while it is running; B.this program cannot run as it contains one and only one syntax error; C.this program cannot run as it contains more than one syntax error; D.this program runs without crashing and allows 5 marks to be entered; E.this program runs without crashing and allows only 4 marks to be entered.

17 20.Consider the following creation of an array, name, to store a list of names: String[] name = new String[25]; Which of the following is the correct way of entering the name “Faith” into the last position of the array? A.name.last = [“Faith”]; B.name[24] = “Faith”; C.name[25] = “Faith”; D.name.length = “Faith”; E.none of the above.

18 21. Consider the Employee class shown in the UML diagram below: Employee name : String address : String phone : String yearOfBirth : int Employee(String, String, String, int) setAddress(String) getName() : String getAddress() : String getPhone() : String getYearOfBirth() : int calculateAge(int) : int Assuming that this class is accessible to the Java compiler, which of the following statements would NOT result in a compiler error? A.Employee emp1 = new Employee ("845", "5034", "0101", 0); B.Employee emp1 = new Employee ("Patel", "Essex", " ", "1970"); C.Employee emp1 = new Employee ("Patel", "Essex", "1970"); D.emp1 Employee = new Employee ("Patel", "Essex", " ", 1970); E.Employee emp1 = new Employee ("Patel", Essex, , 1970);

19 Employee name : String address : String phone : String yearOfBirth : int Employee(String, String, String, int) setAddress(String) getName() : String getAddress() : String getPhone() : String getYearOfBirth() : int calculateAge(int) : int 22.Assuming that an object called emp1, of the Employee class in question 21, has already been created, which of the following statements would cause the address of emp1 to be displayed on the screen? A.System.out.print(address); B.System.out.print(emp1.Address); C.System.out.print(emp1.getAddress()); D.System.out.print(emp1.getAddress); E.System.out.print(getAddress());

20 23.Study the following program (which assumes that the Employee class is accessible to the compiler), and then choose the correct statement from those that follow: public class EmployeeTester { public static void main(String[] args) { Employee emp = new Employee("Mary", "London", " ", 1981); System.out.print(emp.calculateAge(2006)); } A.the above program will not compile; B.the above program compiles successfully and results in the following output: The employee's age is 25 C.the above program compiles successfully and results in the following output: Mary's age is 25 D.the above program compiles successfully and results in the following output: 25 E.the above program compiles successfully and results in the following output: 24

21 public class SomeClass { private int one; private int two; public SomeClass() { one = 2; two = 4; } public SomeClass(int x, int y) { one = x; two = y; } public void setOne(int x) { one = x; } public void setTwo(int x) { two = x; } public void equalize() { one = two; } public int calcSum() { return (one + two); } public int calcDiff() { return (two - one); } 24.Consider the following program which uses SomeClass (as defined above), and choose the correct statement from those that follow: public class SomeProg { public static void main(String[] args) { SomeClass myClass = new SomeClass(); myClass.equalize(); System.out.print(myClass.calcSum()); } A.the program will not compile successfully; B.the program compiles successfully and produces an output of 4; C.the program compiles successfully and produces an output of 2; D.the program compiles successfully and produces an output of 8; E.the program compiles successfully and produces an output of 6.

22 public class SomeClass { private int one; private int two; public SomeClass() { one = 2; two = 4; } public SomeClass(int x, int y) { one = x; two = y; } public void setOne(int x) { one = x; } public void setTwo(int x) { two = x; } public void equalize() { one = two; } public int calcSum() { return (one + two); } public int calcDiff() { return (two - one); } 25.Consider the following program which uses SomeClass (as defined above), and choose the correct statement from those that follow: public class SomeProg { public static void main(String[] args) { SomeClass myClass = new SomeClass(3, 2); myClass.setTwo(1); System.out.print(myClass.calcDiff()); } A.the program will not compile successfully; B.the program compiles successfully and produces an output of 2; C.the program compiles successfully and produces an output of -1; D.the program compiles successfully and produces an output of 1; E.the program compiles successfully and produces an output of -2.


Download ppt "1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual."

Similar presentations


Ads by Google