You are on page 1of 15

CU HI N TP JAVA

K16TCD1

1. What is the main difference between a program written by object oriented language and procedure language? Program written by OOP=set of classes Program written by PP= set of modules 2. What are the members of a class? Members of a class: methods(behavior,action) Member variable(field,attribute) 3. Are imperative statements or descriptive statements ussed to define actions? Imperative statements : define actions Descriptive statements : variable declaration ,method declaration 4. What are the stages in program development process? Understand requirement (analysis) Select solution(design) Coding Testing 5. (bo) What are language elements in Java? Character set,keyword,identifier,comment True

6. Given that b is a boolean variable, what's the value of (b || !b) ? 7. Does the following code int i; i=i+1 have any error? What is it? 8. Are the identifier of the class and the file valid? a . Hello class and hello.java file b. 2Hello class and 2Hello.java file c. Session02 class and Session02.java file 9. Which data types of variables which have default value is null ? 10. In Java, what is the maximum value of a byte variable? a. 127 b. 255 c. 128 11. What is output of the following code? class Demo { public static void main(String[] args) { int x = 4, y; i chua khoi tao gia tri

Reference data type

y = x++; y = ++x; x++; System.out.println(++x); System.out.println(y++); } } In ra : 8 6 12. Find out errors of the following code class ArithmeticDemo { public static void main(String[] args) { int i = 37, j = 42; double x = 27.475, y = 7.22; System.out.println("\ti + j = " + i + j); System.out.println("\ti - j = " + i - j); bi loi System.out.println("\ti / j = " + i / j); System.out.println("\tx / y = " + x / y); System.out.println("\ti / y = " + i / y); System.out.println("\tx % y = " + x % y); } } 13. Which one of the following features of Java enables maximum portability and dynamic capability for programs written in the Java programming language? a. Java is a compiled language b. Java is an object oriented language c. Java is a multithreaded language d. Java is an interpreted language 14. You want to declare a variable of datatype, String in your Java program. Which one of the following options should you use? a. String variable_name = 'Mary'; b. String variable_name = "Mary"; c. String variable_name = Mary; d. String variable_name = "Mary'; 15. You want to create a public class named MyClass in her Java program. Which one of the following syntax should you use ? a. public class MyClass [//code]; b. public class MyClass [//code] c. public class MyClass {//code}; d. public class MyClass { //code} 16. Java runs on _______. d. Windows e. Unix/Linux f. Macs g. All of the Above 17. What is the value of a? int a = 7, b = 4; a += b;

a = a + 1; One answer only a. 5 b. 12 c. 7 d. 8 18. What output will the following lines produce? System.out.println("The answer is: "+17+3); One answer only a. The answer is: 20 b. The answer is: 17+3 c. The answer is: 173 d. The answer is: 19. What is the value of x? int x = 13/5; One answer only a. 2 b. 3.0 c. 2.6 d. 3 20. What is the value of y? int y = 19 % 4; One answer only a. 2 b. 3 c. 4 d. 4.75 21. What will be the outcome of executing following code. class MyClass { public static void main(String []args) { final int i = 100; byte b = i; System.out.println(b); } } a. Will give compilation error (found int, required, byte) b. Will compile and print 100 c. Will throw an exception 22. OOP stands for: a. Observable Object Programming b. Object Observed Procedures c. Object Oriented Programming d. Object Overloading Practices

23. Byte code is the machine language for a hypothetical computer called: a. Java Byte Code Compiler b. Java Byte Code Interpreter c. Java Virtual Machine d. Java Memory Machine

24. Java allows for three forms of comment a. // single line, ** block lines, /*/ documentation b. // single line, /*...*/ block lines, /**...*/ documentation c. ] / single line, /* block lines, ** documentation d. // single line, //...// block lines, //*...*// documentation 25. In Java, the name of the class must be the same as the name of the .java file a. false b. true - but case sensitivity does not apply c. true - but additional numbers must be added to the name d. true

26. What results from attempting to compile and run the following code? public class Ternary { public static void main(String args[]) { int a = 5; System.out.println("Value is - " + (a < 5 ? 9.9 : 9)); } } a. Value is 9 b. Value is 5 c. Compilation error d. Value is - 9.9 27. Which data type is not primitive data type? a. array b. char c. float d. boolean 28. What will be the outcome of executing following code. int x = 4, y; y = x++; System.out.print(x = + (++x) + , y = + y); System.out.print(); a. b. x = 4, y = 5 x = 6, y = 4

c. x = 5, y = 4 d. x = 6, y = 5 29. A program written in the Java programming language can run on any platform because... a. Java programming language is derived from C++ b. The Java Virtual Machine (JVM) interprets the program for the native operating system c. The compiler is identical to a C++ compiler d. The APIs do all the work 30. You store java source code files with following extension ? a. java b. class c. src d. javadoc 31. What are two kinds of data types in Java? Primitive data type Reference data type(array,class,interface) 32. What data types does primitive type include? Primitive data type (integral .floating point,Boolean) 33. What data types does integral type include ? Intergral(byte.short,int,long,char) Floating point (float,double) 34. What are three kinds of operators? Infix: x+y Prefix: ++x Postfix: x++ 35. What is the different between operand promotion rules and casting? Casting: quy tac chuyen kieu:tu minh dua ra cu phap chuyen kieu Operand promotion rule:quy tac nang cap cac toan hang:java tu dong nang cap toan hang 36. What are three kinds of Java statements? single statement Compoumd statement ( block ) Control structure 37. What are the kinds of control structures? Conditional structure : if , switch Loop : for , while , do while Other control structure break , continue

38. How are if statement and switch statement different? Control flow Conditional expression Condition expression if: boolenan Switch : byte, short , int , char Control flow : if 2 flows

39. Present syntax of if and if else statements and give example for each syntax? 40. Can you tell me about ways to express allogithms? 41. Let tell me about the symbols using in flow chart? 42. What are not valid in the following code? if (2 == (100 49*2 )) int n = 2 / 7; Sa li: if(2==(100-49*2)){ int n=2/7; } Hay: Int n; If(2==(100-49*2)) N=2/7; 43. What is the final value of number in the following code? int number = 0 ; if( 2 != (100 49*2 ) ) ; number = 2; number = 2 44. Given: public class Operator { public static void main(String args[]){ int x =1; int y=3; if ((x!=1) && (y++ == 3)) y = y +2;

} } What is the final value of y? a. 3 b.4 c.5 d.6

45. What will be the outcome of executing following code. public class Operator { public static void main(String args[]) { int x=1; int y=3; if ((x==1) && (y++= =3)) y=y+2; System.out.println(++y) ; } } a. 4 b.5 c.6 d.7

46. Is the following code valid or invalid? boolean b; switch( b ){ default : int n = 3; } p n: b must be byte, short, int, char, cant be boolean 47.What will happen when you attempt to compile and run the following code? int Output = 10; boolean b1 = false; if((b1 == true) && ((Output += 10) == 20)) { System.out.println("We are equal " + Output); }

else { System.out.println("Not equal! " + Output); } a. Compilation error, attempting to perform binary comparison on logical data type b. Compilation and output of "We are equal 10" c. Compilation and output of "Not equal! 20" d. Compilation and output of "Not equal! 10" 48. What is the output ? class VD{ public static void main(String args[]) { boolean flag = false; if ( flag = true) { System.out.println("true"); } if ( flag == false) { System.out.println("false"); } } } a. true b.false

c. Compile-time error: "Incompatible type for declaration. Can't convert boolean to java.lang.Boolean" d. true false 49.What is the output ? class Q1{ public static void main(String args[]){ byte b = 65; switch (b) { case 'A': System.out.println("A");

break; case 65: System.out.println("65"); break; default: System.out.println("default"); } } } a. b. c. d. e. A 65 Compile time error , case 65 : duplicate case label Runtime error "Duplicate case label: 65" default

50. What is the compiler error generated by the following piece of code . class Jelly{ public static void main(String args[]){ float f = 1. /2; if (f==0) System.out.println(Integral division); else System.out.println(Floating point division); } } a. b. c. d. e. float f = 1. / 2 : invalid numeric type float f = 1. / 2 : explicit cast needed to convert int to float System.out.println (f) : can't invoke a method on primitive data types No problem, the code compiles fine . float f = 1. / 2 : explicit cast needed to convert double to float

(hang 1.=1.0 la hang doulbe, khong the gan cho float f 51. You have used the following declaration in your Java program: class MyClass {

float aFloat; }
a. b. c. d.

Which type of variable have you declared?

A final variable A static variable. An instance variable A class variable 52. The general syntax for the while statement used in Java programs is: while (expression) { statement }. Which one of the following statements is valid? a. The while statement continually executes a block of statements while a condition remains true b. The while statement continually executes a block of statements while a condition remains false c. The while statement continues testing the expression and executing its block until the expression returns true d. The while statement evaluates expression, which must return an integer value. 53. You want to write a Java program to display the grades based on the percentage obtained by each student in a particular test. Which one of the following options should you use ? a. The for statement b.The while statement c. The do-while statement. d.The if-else statement 54. You have declared the following array in your Java program: int[ ] myArray. Which one of the following statements should you use to allocate memory for the array? a. myArray = int(10); b.myArray = int[10]; c. myArray = new int[10]; d.myArray = new int; 55. Sara has written the following code: class First { int i ; int j ; int k; }. She wants to create an object of the class and assign values to the data members. Which one of the following options should she use to create the object? a. First f = First() b.First f = First c. First f = new First d. First f = new First() 56. You create an array of objects in your Java program. Each of these objects is automatically initialized to a special value with its own keyword. Identify the keyword a. Init b. val c. null d.main 57. All classes in Java inherit from one general class. Identify the class a. Object b. System c. Language d.Database 58. You have declared an array in your Java program. You want to write a line of code in your program to display the number of elements in the array. Which one of the following options should you use? a. The length method b. The length property c. The arrayLength method d. The arrayLength property 59. Tom is writing a program in Java. He wants to declare a variable such that there is only a single copy of the variable and it is shared by every object instantiated from the class. Which one of the following options should he use? a. Tom should declare the variable as an instance variable b. Tom should declare the variable as a final variable. c. Tom should declare the variable as a static variable. d. Tom should declare the variable as a temporary variable 60. In Java, only public package members are accessible outside the package in which they are defined. There are different ways to access a public package member from outside its package. Identify the incorrect option

a. b. c. d.

Refer to the member by its simple name Refer to the member by its long (qualified) name java.util.Scanner Import the package member import java.util.Scanner; Import the members entire package import java.util.*; 61. Your java program contains a class named MyClass. You want to include it in a package named mypackage.myclass. Identify the correct location of the MyClass.java file for proper code execution a. mypackage/MyClass.java b.myclass/MyClass.java c. mypackage/myclass/MyClass.java d. myclass/mypackage/MyClass.java 62. Mary is writing a Java program to create an interactive user application. She wants to use the members of the AWT package in her program. Identify the correct syntax. a. import java.awt.*; b. include java.awt.*; c. import awt.*; d. include awt.*; 63. You want to create your own package in your Java program. Which one of the following statements is a valid statement in this context? a. Multiple package declarations can appear in a source file. b. Only one package declaration can appear in a source file. c. A package declaration should appear at the end of the source file d. A package declaration should appear after the class declaration in the source file. 64. Jack wants to create Java programs that can run in the browser. Which one of the following packages should he use? a. The net package b. The applet package c. The awt package d.The utility package. 65. Identify the package in the Java API which provides classes that are fundamental to the Java programming language. a. The io package b. The awt package. c. The system package d.The lang package. 66. Which one of the following options is a collection of related classes and interfaces providing access protection and namespace management in Java? a. Class b. Package c. Interface d. Collection 67. Identify the superclass of all errors and exceptions in the Java language a. Exception b. Error c. Throwable d. Runnable 68. What will the following code snippet print? int a[][] = {{1,2,3},{2,3,4}}; int tong = 1; for (int i=0; i<a.length -1;i++) for (int j=0; j<a[i].length -1;j++) tong = tong + a[i][j]; System.out.println(Tong la :+tong); 69. What will the following code snippet print? int a[] = {1,2,3,4,7}; int tong = 1, i = 0;

while (i < a.length -1) { if (a[i] % 2 !=0) tong = tong + a[i]; i++; } System.out.println(Tong la :+tong); 70. What will the following code snippet print? int i=0,t=2; int a[] = {2,6,3,4}; while (i<a.length-1) { if (a[i] % 2 ==0) t +=a[i]; i++; } System.out.println(t=+t); 71. What will the following code snippet print? int s=2; int a[][] = {{2,4,6},{1,2,3}}; for (int i=0; i<a.length-1;i++) for (int j=0;j<a[i].length;j++) s = s+a[i][j]; System.out.println(s=+s); 72. What will the following code snippet print? int[] a = {1,4,3,7,8,3,9}; int s=5; for (int i=1; i<a.length;i=i+2) if (a[i] % 2 != 0) s = s + a[i]; System.out.println(s=+s); 73. What output does the program produce? String a[] = new String[4]; a[0] = "Alpha"; a[1] = "Beta"; a[2] = "Delta"; a[3] = "Gamma"; for (int i = 0; i < 4; i++) System.out.println((i+1) + " " + a[i]); System.out.println(The end of array);

74. What is the output of following code? class Tinh { private int a, b; public Tinh(int a, int b) {

this.a = a; this.b = b; } public void hienThi(int a) { System.out.println(Ket qua tinh la: + a*b); } public static void main(String args[]) { Tinh v = new Tinh(2,4); v.hienThi(3); } } 75. class ViDu { private int a, b; public ViDu(int a, int b) { this.a = a; this.b = b; } public void ketQua() { int a = 2, b = 6 ; System.out.println(Ket qua tinh la: + a*b); } public static void main(String args[]) { ViDu v = new ViDu(3,7); v.ketQua(); } } 76. class KetQua { private int a, b;

public KetQua(int a, int b) { this.a = a; this.b = b; } public void tinh(int b) { int a = 12; System.out.println(Ket qua tinh la: + this.a*b); } public static void main(String args[]) { KetQua kq = new KetQua(5,2); kq.tinh(4); } } 77. Write the declaration (no definition) of following methods a. The method is object method, named tinh, returns a double, passed two parameters, a double and a string and used anywhere b. The method is static method, named trungBinh, returns a double, passed two integer parameters, used in the same package c. The method is class method, named xuLy, returns a string, passed two double parameters, used anywhere d. The method is instance method, named hienThi, passed string parameter, returns a integer, used in the same class e. The method is instance method, named hienThi, passed string parameter, returns a integer, used in the same class and its subclass Tr li cc cu hi trn website sau, b qua cc cu hi lin quan n lp trnh giao din ha, v b qua cc cu hi lin quan n ni dung khng hc Ch tr li cu hi java test 1 trc, c nhiu cu hi v lp trnh c bn , lp trnh hng i tng trong java test 1 Truy cap trang nay: http://examineonline.googlepages.com/Java_182.htm hay http://examineonline.googlepages.com/Java.htm chn Open, va su dung IE

You might also like