Part A

:

True/False Questions

1. The name of a Java program file must match the name of the class with the extension .java A. True B. False 2. Two methods cannot have the same name in Java. A. True B. False 3. The modulus operator (%) can be used only with integer operands. A. True B. False 4. Declarations can appear anywhere in the body of a Java method. A. True B. False 5. All the bitwise operators have the same level of precedence in java. A. True B. False 6. When x is a positive number, the operations x > > 2 and x > > > 2 both produce the same result. A. True B. False 7. If a = 10 and b = 15, then the statement x = (a > b )? a : b; assigns the value 15 to x. A. True B. False 8. In evaluating a logical expression of type
boolean expression1 && boolean expression2

both the boolean expressions are not always evaluated. A. True B. False 9. In evaluating the expression (x = = y && a < b) the boolean expression x = = y is evaluated first and then a < b is evaluated. A. True B. False

400

Programming with Java: A Primer

10. The default case is always required in the switch selection structure. A. True B. False 11. The break statement is required in the default case of a switch selection structure. A. True B. False 12. The expression (x = = y && a < b) is true if ether x = = y is true or a < b is true. A. True B. False 13. A variable declared inside the for loop control cannot be referenced outside the loop. A. True B. False 14. Java always provides a default constructor to a class. A. True B. False 15. When present, package must be the first noncomment statement in the file. A. True B. False 16. The import statement is always the first noncomment statement in a Java program file. A. True B. False 17. Objects are passed to a method by use of call-by-reference. A. True B. False 18. It is perfectly legal to refer to any instance variable inside of a static method. A. True B. False 19. When we implement an interface method, it should be declared as public. A. True B. False 20. We can overload methods with differences only in their return type. A. True B. False 21. It is an error to have a method with the same signature in both the super class and its subclass. A. True B. False 22. A constructor must always invoke its super class constructor in its first statement. A. True B. False 23. Subclasses of an abstract class that do not provide an implementation of an abstract method, are also abstract. A. True B. False 24. Any class may be inherited by another class in the same package. A. True B. False 25. Any method in a super class can be overridden in its subclass. A. True B. False 26. One of the features of Java is that an array can store many different types of values. A. True B. False 27. An individual array element that is passed to a method and modified in that method will contain the modified value when the called method completes execution. A. True B. False 28. Members of a class specified as a private are accessible only to the methods of the class. A. True B. False 29. A method declared as static cannot access non-static class members. A. True B. False 30. A static class method can be invoked by simply using the name of the method alone. A. True B. False 31. It is an error, if a class with one or more abstract methods is not explicitly declared abstract. A. True B. False

True B. False 46. A. False 39. A. A final class may not have any abstract methods. A. False 42. True B. A. True B. A. Declaring a method synchronized guarantees that the deadlock cannot occur. False 50. True B. A.out objects. Every call to wait has a corresponding call to notify that will eventually end the waiting. False 37. True B.in and System. we can use an instance of class File. False 47. A panel cannot be added to another panel. Frames and applets cannot be used together in the same program. A. A. False 45. True B. A. False 36. True B. If the file-position pointer points to a location in a sequential file other than the beginning. False 44. Throwing an Exception always causes program termination. A class may be both abstract and final. False 52. . When the String objects are compared with = =. All methods in an abstract class must be declared abstract. A. False 51.Appendix K: SCJP Exam Model Questions 401 32. False 48. A thread wants to make a second thread ineligible for execution. A. A. True B. False 35. False 38. True B. To delete a file. the result is true if the strings contain the same values. True B. A. True B. A catch can have comma-separated multiple arguments. False 40. False 34. to read from the beginning of the file again. To achieve this. True B. True B. A. True B. A. A thread can make a second thread ineligible for execution by calling the suspend( ) method on the second thread. Every method of a final class is implicitly final. True B. the first thread can call the yield( ) method on the second thread. It is perfectly legal to assign a subclass object to a super class reference. True B. A. It is an error to catch the same type of exception in two different catch blocks associated with a particular try block. True B. True B. False 49.length. False 41. A. A. The programmer must explicitly create the System. A. True B. False 33. False 43. True B. we must use the seek method to bring the pointer to the beginning. It is perfectly legal to assign an object of a super class to a subclass reference without a cost. A String object cannot be modified after it is created. A. The length of a String object s1 can be obtained using the expression s1.

int a = 16. the component at the centre gets all the space that is left over. The range of values for the long type data is A. False 57. then assigning the return value to a variable of type String may cause an exception to be thrown.402 Programming with Java: A Primer A. What will be the result of the expression 13 & 25? A. A Java monitor must either extend Thread class or implement Runnable interface. True B. If a frame uses a Grid layout manager and does not contain any panels. False 59. False 60. With a Border layout manager. The default value of char type variable is A. A. 18 C. If getParameter( ) returns null. True B. then all the components within the frame are of the same width and height. The CODE value in an <APPLET> tag must name a class file that is in the same directory as the calling HTML page. int a = 16. False 53.4. a >>> 2 = 4 . False 58. Which of the following assignments are valid? A. 1 B. A. 9 D. Which of the following are correct? A. –232 to 232 – 1 2. float x = 123. 0X9F D. double y = 0X756. What will be result of the expression 9 | 9? A. It is possible to use the File class to list the contents of the current working directory. True B. D. long m = 023. None of the above 7. Reader class has a method that can read and return floats and doubles. 38 B. False Part B: Multiple-choice Questions 1. ‘\u00ff C. 25 C. True B. B. True B. A. 12 6. b >> 1 = –4 C. 0X5 3. 4. True B. ‘\u0000’ 5. (hex) 5 C. A. True B. The CheckboxGroup class is a subclass of the Component class. True B. int b = – 8. A. “ “ D. C. after the components at North and South have been considered. ‘\u0020’ B. –2 D. False 54. int n = (int)false. a >> 2 = 4 B. 9 D. –231 to 231 – 1 B. False 56. A. A. Which of the following represent(s) of a hexadecimal number? A. 570 B. A. True B. False 55. –264 to 264 63 to 263 – 1 C.

A. 15. 4 B. –2 What will be the value of x after executing these statements? A. abs(x) C.34. 10.9? A. D. + = D. int b = –8. 8 D. –4 E. round(x) E. abs(x) E. 1 C. Consider the following statements: int x = 10. boolean x = (boolean)10. 5 E. What will be the values of x. . 15 D. floor(x) B. What is the result of the expression (1 & 2) + (3 | 4) in base ten. n. what will be the result of the expression m % n when m = 5 and n = 2? A. m. rint(x) D. Which of the following will produce a value of 10 if x = 9. + +m + n++. n = 16 D. b >>> 1 = – 4 E.Appendix K: SCJP Exam Model Questions 403 D. 2 C. ceil(x) B. m = 11. None of the above 11. None of these 13. 3 14. rint(x) D. If m and n are int type variables. m = 11. Which of the following operators are overloaded for String objects? A. (10 | 5) B. + C. If m and n are int type variables. 1 B. 2 D. Error. 7 E.7? A. << F. Which of the following expressions are illegal? A. round(x) C. m. C. x = 27. x = ( (x<y) ? (y+x) : (y — x) . & E. 12. (false && true) C. 25 C. – B. and n after execution of the following statements? int m = n = x = x. what will be the result of the expression m % n when m = – 14 and n = –3? A. n = 16 9. None of the above 10. n = 15 B. m = 10. y = 15. Which of the following will produce a value of 22 if x = 22. n = 15 C. x = 27. Cannot be executed. x = 25. x = 26. A. floor(x) 15. 0 B. m = 10. All the above 8. float y = 12. 2 D. 10 B. ceil(x) 16.

println (“Number is positive”) . sum = 0. 19. System. Line 3 only C. Which of the following control expressions are valid for an if statement? A. Line 4 only D. int i = 10. None of the above 22. a boolean expression C. int j = 0. while(j < 10) { 3. an integer expression B. byte b1 = 5. None of the above 20. Which of the following lines will not compile? 1. for(int i = 10. Line 3 and Line 4 only 18. while (i) { Body statements } D. Line 1 only B.println (“Number is negative”) . while(int i > 0) {i. i = i – 2. b2 = s. either A or B D. int j = 0.404 Programming with Java: A Primer 17. Both A and B D. Consider the following code if (number >= 0) if (number > 0) System. Line 1 and Line 4 only E. In the following code snippet. What will be the output if number is equal to 0? A. i+j > 5. Consider the following code: char c = ‘a’ .out. 4. if(j = = 5) continue loop. Which of the following are illegal loop constructs? A. else System. Line 3 C.println(“j is” + j). int i = 1. Number is negative B. Line 2 B.-. 2. Neither A nor B 21. b3. which lines of code contain error? 1.} B. 5. other statements. Line 4 D. A. b3 = b1 * b2. j++) { Body statements } C. do {loop statements} while(sum < 10 || i<5). j+ +. Line 5 E. short s = 25. switch (c) { . } A. 3. 4. 2. Number is positive C.out. b2 = 3.out.

and then followed by C D. What is wrong in the following class definitions? abstract class Print { abstract show ( ) .println (“B”) . int y) { } } A. } 405 For this code. Method is not defined properly D. class Student extends String { } What happens when we try to compile this class? A. Method show( ) is not implemented in Display D. Nothing is wrong B. Constructor is not defined C. case ‘b’ : System.Appendix K: SCJP Exam Model Questions case ‘a’ : System. Will compile successfully. Consider the following class definitions: class maths { . which of the following statement is true? A.println (“A”) . output will be A followed by B C. Will not compile because String is final E. Class header is not defined properly B. Wrong.out. 24. Method show( ) should have a return type C. Will not compile because the class is not declared public C. Will not compile because class body is not defined B. What is the error in the following class definition? abstract class XY { abstract sum (int x. output will be A.out. Consider the following class definition. Will not compile because String is abstract D. followed by B. output will be A B. No error 26. Display does not contain any members 25. Wrong. } class Display extends Print { } A.println (“C”) . default: System. code is illegal and therefore will not compile 23.out. Wrong.

int z) { } B. 4. int y. y) . float sum(int x. float sum(int x. Method display( ) should be declared as static C. Which of the following statements are true? 1. B. 2. A a = new A(5. int y. C. 5). A a = new A(10). float y) { } D. Test class should be declared as public 30. neither 27. Test class should be declared as abstract D. } } Which of the following are legal statements to construct A type objects? A. int sum(float x. Consider the following class definition: class A extends B { public A (int x) { } public A (int x. D. We cannot use abstract classes to instantiate objects directly. 7). } A. float z) { } 29. 6). What is the error in the following code? class Test { abstract void display ( ) . A a = new A(4. No error B. int sum(int a. int y) { } C. E. int sum(int x. 2. both D. int y) { } A. 6). A a = new A( ). int y) { super (x. We may declare abstract static methods. 3.406 Programming with Java: A Primer Student student1. Which of the following are overloading the method int sum(int x. } class Student { String name. a ‘has a’ relationship C. We cannot declare abstract constructors. The abstract methods of an abstract class must be defined in its subclass. . } This code represents: A. A a = new A(Base(4. an ‘is a’ relationship B. int b) { } E. 28.

Error. protected C. } ClassA (int x) { } } class ClassB extends ClassA { } What will happen when we compile and run this code? A. integer C. extended E. protected D. Visible in all classes in the same package and subclasses in other packages D. union B. private B. Visible only in the class where it is declared. public D. implements C.Appendix K: SCJP Exam Model Questions 407 31. object Which of the following keywords are used to control access to a class member? A. Error. line 2 and line 3 only E. Line 1 only B. Visible only inside the same package. A. ClassB does not define a no-argument constructor D. Line 2 only C. inner D. C. default D. Which one of the following keywords would achieve this? A. B. There is no code in the class ClassB E. private B. ClassA does not define a no-argument constructor C. 37. 38. boolean E. 32. Visible only in the class and its subclass in the same package. Line 1 and line 2 only D. Which of the following are not keywords? A. 33. don’t use any keyword at all (make it default) We would like to make a member of a class visible in all subclasses regardless of what package they are in. NULL B. synchronized Consider the following code: class ClassA { public static void main (String args [ ] ) { ClassB b = classB ( ) . protected C. final D. private protected The use of protected keyword to a member in a class will restrict its visibility as follows: A. const C. Error. protected D. switch B. Compile and run successfully B. 35. There is no code in the constructor ClassA (int x) . default B. All are true Which keyword can protect a class in a package from accessibility by the classes outside the package? A. public The keywords reserved but not used in the initial version of Java are: A. 36. interface E. 34. Line 1. abstract C. boolean F. string Which of the following are keywords? A. goto E. Error.

B. D. C. Test t1. Consider the following code: interface Area { float compute (float x. }} 42. float y) { . A final class may not have any abstract methods. An abstract class may not have any final methods. editing tools D. Student class is not available. B. 41. 43. Which of the following statements are true? A. A package is a collection of A. Result body is not fully defined. C. Class Result should be declared public. abstract class Vehicle { abstract void display( ). Which of the following defines a legal abstract class? A. float y) . classes and interfaces 40. class abstract Vehicle { abstract void display( ). Transient variables must be static.out. Package p1 contains the following code: package p1.println(“Car”). Test class is not available. abstract class Vehicle { abstract void display( ). class Vehicle { abstract void display( ). } This code will not compile because A. } D. D. interfaces C.*. class Result { Student s1.408 Programming with Java: A Primer 39. } E. } class Room implements Area { float compute (float x. } B. public class Student { Body of student } class Test { Body of Test } Now consider the following code: import p1. { System. } C. classes B. An inner class may be declared with any accessibility keyword. abstract Vehicle { abstract void display( ).

number[2] is 0 E. number[4] is null D. Random E. all the above 45. else table [i] [j] = 0.length( ) is 5 47. Byte C. C. Interface definition is incomplete B. All the above 44. Consider the following code int number [ ] = new int [5] . counter int[ ]. 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 1 1 1 1 0 0 48. StringBuffer G. Random B. Which of the following statements are valid array declaration? A. Which of the following classes are available in the java. int[ ] y = new int[5]. int x[ ] = int[10]. D. B. number[5] is undefined C. String 50. B. Stack B. Math D. D. Short F.lang package? A. Which of the following contain error? A. Vector D. Which of the following are the wrapper classes? A. int number( ). A. j<3. The concept of multiple inheritance is implemented in Java by A.Appendix K: SCJP Exam Model Questions return (x & y) . 0 0 0 B. Object C. j++) if (j == i) table [i] [j] = 1. which of the following are true? A. Vector 49. } } 409 What is wrong with the code? A. implementing two or more interfaces D. String F. 46. 1 0 0 0 1 0 0 0 1 . After execution of this statement. i+ +) for (int j=0. 1 0 0 C. extending one class and implementing one or more interfaces C. extending two or more classes B. Integer E. double[ ] marks. number[0] is undefined B. Method compute( ) in interface Area should be declared public C. number. Method compute( ) in class Room should be declared public D. float average[ ]. Double G. i<3. What will be the content of array variable table after executing the following code? for (int i=0.

String B. Which of the following methods belong to the String class? A. 51. 10 20 20 B. int a[ ] = {1. 57. equals( ) D.equals(s1) 53.replace(‘a’. catch block. The statement System.setCharAt(1. s1 = = s2 B.x + “ ” + d.append(“xyz”) 55. E. C. D.println (b. Base bd = new Derived( ) . String s3 = s1 – s2. B. java. s1 <= s2 D. } class Derived extends Base { int x = 20. Given the class definitions class Base . D..ThreadGroup 56. Which of the following calls are valid? A. None of them 52. 20 10 20 D. The sleep( ) method should be enclosed in try . 2}.lang. E.lang. s. String s3 = s1 + s2.length( ). F. java. compareTo( ) C. 10 20 10 C. 2. int i = new int(10). Given the code String s1 = “yes”. Derived d = new Derived( ) . Which of the statements or expressions are correct? A.‘A’) F. A Java monitor must either extend Thread or implement Runnable. s3 = = s1 D.. Suppose that s1 and s2 are two strings..substring(3) D.equals(s2) E. 54.trim( ) B. A suspended thread using suspend( ) method can be revived using the resume( ) method. s.lang. java. b = a.lang. The yield( ) method should be enclosed in try .toUpperCase( ) E. Which of the following would equate to true? A. s3. The methods wait( ) and notify( ) are defined in A.lang. int m = s1. s. A thread can be temporarily suspended from running by using the wait( ) method. 3}. All of them F. Which of the following statements are true? A. s1. catch block. ‘A’) C.Thread E.compareTo(s2). 20 20 10 58.410 Programming with Java: A Primer C.x) . substring( ) E. int b[ ]. Given the code String s = new String (“abc”) . E. s1 = s2 C.x + “ ” + bd.. String s3 = new String (s1) . x = y = new int [10]. float d[ ] = {1. s. B. String s2 = “yes”.Runnable C. C. } Base b = new Base ( ) . s1. will produce the output A.Object D. Given the following code: class Base { int x = 10. java. length( ) B.out. java. s. s.

out. paint( ) 60.out. < applet code = Test. Base Derived Derived D. } } 411 and objects Base b = new Base( ).class width = 200 height = 100> < /applet> C.out.display( ) + “ ”). Base Base Derived B. Creates text object that can hold 10 columns of text.println (“Derived”) . < applet> code = Test. Creates the object text and initializes it with the value 10. When we invoke repaint( ) for a Component. The code is illegal.print(bd. 61.out.println (“Base”) . will display: A.class width = 200 height = 100 < /applet> D. What does the following line of code do? TextField text = new TextFiled(10).class width = 200 height = 100> < /applet> . then the print statements System.Appendix K: SCJP Exam Model Questions { void display( ) { System.out. the AWT invokes the method: A. update( ) D. A. Which of the following applet tags is legal to embed an applet class named Test into a Web page? A. show( ) C. Base Derived Base C.display( ) + “ ”). Base bd = new Derived( ). Derived d = new Derived( ). System. System.print(b.out. B.display( ) + “ ”). System.println( ). C. Derived Derived Derived 59. draw( ) B.print(d. < applet class = Test width = 200 height = 100> < /applet> B. < applet param = Test. Creates text object that can hold 10 rows of text. } } class Derived extends Base { void display ( ) { System. D.

setSize( ) C. “ wr ” E. runnable( ) E. 64. size( ) E. “ rw ” D. XXX followed by YYY D. hide( ) E. main( ) Which of the following strings can be used as mode strings for creating a RandomAccessFile object? A. move( ) The setBackground( ) method is part of the class A. What will be output of the following program? class Main2 { public static void main(String args[ ]) { boolean b = true. Error. System. System. remove( ) C. we must define the method A. Graphics B. resume( ) F. fillRect( ) B. “ w ” C.out. area( ) D. System. disappear( ) D. Applet C. } } . } } A. 63. drawLine( ) C.class width = 200 height = 100> < / applet> Which of the following methods can be used to draw the outline of a square? A.println(“YYY”). Won’t compile 69. < applet code = Test. run( ) D. Container E.println(“XXX”). Component D.out. resize( ) Which of the following methods can be used to remove a component from the display? A. drawPolygon( ) Which of the following methods can be used to change the size of a component A. 66. init( ) C. Object When we implement the Runnable interface. delete( ) B. if( !b ) return. drawRect( ) D. YYY C. start( ) B. “ r ” B.412 Programming with Java: A Primer 62.println(“YYY”). drawString( ) E. E. 67. System. XXX B. return.out.out. 65. 68. dimension( ) B.println(“XXX”). “ 0 ” What will be the output of the following program? class Main1 { public static void main(String args [ ]) { boolean b = true.

To provide information about deprecated methods D. new DataInputStream(“in. a class we can use to read primitive data types. x = b1 * b2. Error. 73.dat”). new DataInputStream(new FileInputStream(“in. A. YYY C. new DataInputStream( ). number = getParameter(99) B. D. 77. < param name = number value = 99 > E.dat”. int C. byte B. Which exception is thrown by the read( ) method of InputStream class? A. “r”). new DataInputStream(new File(“in. an interface that defines methods to read primitive data types. B. //# B. DataOutputStream objects are used to write primitive data to a file. short D. IOException E.io. File class may be used to rename a file. ReadException D. None of the above In the code below. 74. /** D. long E.dat”) D. float F. FileNotFoundException C. //** Given file is a File object. D. < param = radius value = 99 > D. C. 76. new DataInputStream(“in. Exception B. an interface that defines methods to open files. Executing a class with optimization turned off C. XXX followed by YYY D. UTF characters are all 24 bits. B. B. Using the jdb tool B. double If you want to assign a value of 99 to the variable year. Which of the following statements are true? A.Appendix K: SCJP Exam Model Questions 413 70. /* C. XXX B. an abstract class defined in java. C. None of the above With javadoc. A. < number = 99 > C. 71. then which of the following lines can be used within an <applet> tag? A. 78. Unicode characters are all 16 bits.dat”)). < param number = 99 > What is java_g used for? A. 75. which of the following are legal statements to create a new file . C. E. what data types the variable x can have? byte b1 = 5. byte b2 = 10. Won’t compile DataInput is A. 72. Which are the valid ways to create DataInputStream streams? A. E. Reader class has methods that can read integers and floats. which of the following denotes a javadoc comment? A.

the variable x is evaluated to 8. Which of the following command lines options generates documentation for all classes and methods? A.. D.’ B. short y. In which of the following code fragments. byte b1 = — 40. D. int x = 35. –encoding 81. @value 80. b = x1 * 2 = x2. Which of the following statements are evaluated to true? A. C. . FileOutputStream fos = new FileOutputStream(file). n = m * 3L. C. . D. int x = 16. x = x > > 1. x2 = 200. RandomAccessFile raf = new RandomAccessFile(file).. int x = 32.... Given the declarations boolean b. B... B. –public C. Which javadoc tage is used to denote a comment for a method parameter? A.println(“Division by zero”). 83. file. –private D. B. 84. b2.println(“catch block”). try { int x = 0.out. FileWriter out = new FileWriter(file).. b = (x3 – 2*x2<0) || ((x3 = 400) <2**x2). @method B. y = m * b1.. System. A. 82.. –verbose E. } . b = x1 + x2 != 3 * x1. . x = m * 3L.create( )... @param E.. x = x > > 2.out.414 Programming with Java: A Primer A. int x = 33. int y = 50/x. @argument D. C. –protected B. Given the declarations int x. long n. Consider the following code snippet: . } catch(ArithmeticException e) { System. E. x = x > > 2. FileInputStream fis = new FileInputStream(file). x = x > > 2. b = (x3 – 21*x2>0) || (x3 = 400) 2*x2). short x1 = 100. which of the following assignment statements will evaluate correctly? A. m = 2000. 79. x = m * b1. D. x3 = 300... @parameter C. C..

Division by zero C. . D. B. What is the output of the following code? String s. without using if construct.out. Given the value of a variable. System. What does the following fragment display String s = “six:” + 3 + 3.println(m). n2 = 20. Error. } 5. break( ).println(y). y = (byte) (x << 2). while (+ +m < — — n).out. 2. case 2: n3 = 30. write a statement.out. n4 = 40. C. E. 7. Which of the following represent legal flow control statements? A. b = (byte) d. 6. F. System.println(b). break. Part C: Short-answer Questions 1. Catch block D. Won’t compile B. continue outer.out. Division by zero Catch block 85. y. int n = 300. continue(inner). double d = 417.out. What will be the output of the following code: byte b. System. What will be the output of the following program code? int m = 100. break.println(s).println(“s = ” + s). What will be the output of the following code? byte x = 64. exit( ). System.35.Appendix K: SCJP Exam Model Questions 415 What will be the output? A. System. 4. 3. What is wrong with the following code? switch(x) { case 1: n1 = 10. which will produce the absolute value of the variable. return.

b. } else System. j = 10.println(“OK”).out. if(a > 5) if(b > 5) { System. System. Show the output the following code: int a. while(true) { . What is the problem with the following snippet? class Q9 { public static void main(String args[ ]) { int i = 5.416 Programming with Java: A Primer 8. 13. b = 10. if(a > b) { if(b > 5) System.println(“s = ” + s). if ( (i<j) || (i=10) ) System. } else System. State the output of the following code: int a = 10.out.println(“a is ” + a).println(y).println(“a is” + a). 11.out. What is the output of the following code? String s = new String( ).out.println(“b is ” + b).println(“b is ” + b). 9.out. System.println(“NOT OK”). Give the output of the following code: int m = 100.out.out. if ((x<y) || (x=5)>10) System.out. } } 10. 12.out. What will be the output of the following code snippet? int x = 10. else System. int b = 5. a = 5.println(x). int y = 20.

if No: . Consider the following class file? import java.. Given a package named EDU..println(“m is ” + m).println(“RESULTS”).Student. Give the output of the following code: int m = 100. 15.. 17. int y) { . import java.. package studentBase.out.awt.*.*. how would you import a class named Test contained in this package? Write one line statement. m = m — 10.. complete the following class so that it returns x+y if the value of x is equal to y.. Consider the following class definition: class Student { abstract double result( ) } This code will not compile since a keyword is missing in the first line. } Systm.out. Give reason. class Test { void display( ) { System. while(true) { if(m < 10) continue. What is the keyword? 18. m = m — 10. Using a single line of code.out.println(“m is ” + m).. otherwise returns 0: public class XY { public return int fun(int x.Appendix K: SCJP Exam Model Questions if(m < 10) break. 417 14..io. } System.. (one line code her) } } 16. } } Will it compile? YES or NO.

} void method(String s) { System. 21.println(“y = ” + y).out. } } Will it compile? YES or NO. } } Will the file Company. y)). System. } public static void main(String args[ ]) { A a1 = new A( ). y = 20.java compile? YES or NO. Given below are two files: File Employee.00. } int mul(int a. Consider the following code: class A { void method(int x) { System.java import purchase. int b) { return(a * b).out. } } class B extends A { void method(int y) { System. System. Give reason.Employee. Consider the following code: Programming with Java: A Primer class Product { public static void main(String args [ ]) { int x = 10.out. public class Company { public static void main(String arg[ ]) { Employee e = new Employee( ). . if No. Give reason.println(“x = ” + x).println(“Age = ” + e.418 19. if No: 20.age). } File Company.out.println(“s = ” + s).out.println(mu1 (x.java package purchase. public class Employee { protected double age = 35.

out. we can create a new file using two classes defined in java.println((x>y)? 3. Which is the third one? 23. System. } } 25.Appendix K: SCJP Exam Model Questions A a2 = new B( ). What will be the output of the following program when it is executed with the command line java Command Java is wonderful class Command { public staitic void main(String args[ ]) { for(int i = 1.io package. // 0000 0011 short s2 = 13. Which is the other one? 27. } } 24.length ) System.print(“ ”).out. What output will the following program produce? class Bits { public static void main(String args[ ]) { short s1 = 3. // 0000 1101 s1 = (short) (s1 ^ s2).print(args[i]). One is FileOutputStream class.14 : 3)). System.out. i+ +) { System. if( i != args.method(10). i < args. how can we move the file pointer to the end of the file? Write the statement. int y = 15. Given a valid File object reference.length. when executed? 22.io package defines a method to delete a file? 26.method(20). a2. State the output of the following program: class Condition { public static void main(String args[ ]) { int x = 10. a1. If raf is an instance of RandomAccessFile.out. } } 419 What will be the output. There are three classes that implement and DataInput and DataOutput interfaces.println(“Result is ” + s1). 28. } . Which of the classes in java. Two of them are DataInputStream and DataOutputStream.

System. suspend( ). T1. what will be the output? 31. 30.println(“End”). StringBuffer string = new StringBuffer( ). int x2) { if(x1 > x2) max = x1. when executed? . max(max.420 Programming with Java: A Primer System. else max = x2. String. string.append(new String(city)).out.out. 20. } } On execution.out.println(“ ”).println(string). string.out. 30).insert(0. } } What value is printed out. What will be the output of the following code snippet when combined with suitable declarations and run? StringBuffer city = new StringBuffer(“Madras”). } } 29.println(“Begin”). } } class ThreadTest { public static void main(String args[ ]) { Thread1 T1 = new Thread1( ). “Central ”).start( ). int x1. Consider the following program code: class Thread1 extends Thread { public void run( ) { System. Consider the following application: class Max { public static void main(String args[ ]) { int max = 10.println(max).out. System. } static void max(int max. resume( ).

out.println(“x = ” + x). } x = m + n. } } Will this code compile? YES or NO. System.out. System. 34. System. { int n = 30. State the output of the following program: class Recur { public static void main(String args[ ]) { int Result = result(10). public static void main(String args[ ]) { int m = 10.out. static int n = 0.Appendix K: SCJP Exam Model Questions 421 32. Give reason. } } 33. int x = 20.println(“m is ” + m). Consider the class definition: class Default { public static void main(String args[ ]) { int m. if No.println(“m + n = ” + m + n). } static int result(int m) { if (m <= 2) return m. What is the output of the following program? class Static { static int m = 0.println(“Result = ” + Result). } } 35. System. else return m + result(m — 2).out. Consider the following class definitions: class Square { private square( ) { } .

Which line of the following HTML file contains an error? 1. 4. int area = S1. 2.println(area).out.println(s).equals(“X”) . } } class Constructor { public static void main(String args[ ]) { Square S1 = new Square( ). Give the output of the following program: class MainString { public static void main(String args[ ]) { StringBuffer s = new StringBuffer(“String”). Give reason. YES or NO. 6. if(s.length()>5) && (s.Class > < param NAME = “string” VALUE = “Hello” > </applet> 38. 7.append(“Buffer”). // empty statement System. if No. What is the range of the value that can be assigned to a variable of type long? .out. 3. 5. < applet WIDTH = 400 HEIGHT = 200 CODE = HelloJava. 37.area(10). Write a statement to draw a rounded rectangle with the following features: width = 200 height = 100 corner horizontal diameter = 20 corner vertical diameter = 40 Select a suitable upper-left corner of the rectangle. } } Will the code above compile and run successfully. 36.422 Programming with Java: A Primer int area(int side) { return(side * side). System. } } 39.

Appendix K: SCJP Exam Model Questions 423 40. } } What is the output? 41. . catch block: class TryCatch { public static void main(String args[ ]) { try { double x = 0. n. void store(Number num) { num. if( (k%10) == 0) continue loop2. 44.x = 10.j++) loop3: for(int k=0.store(n). Consider the following try .x). Can an abstract method be declared static? YES or NO. n.out. Given the code: class Continue { public static void main(String args[ ]) { int m = 0. i<10. Can an abstract method by declared final? YES or NO. System.k++) { System. loop1: for(int i=0.out. 43.. } } } What is the last value printed? 42. give reason. give reason. Consider the following program : class Number { int x..println(n.j<10.0. If NO.k<10. } } class MainNumber { public static void main(String args[ ]) { Number n = new Number( ).println(++m). If NO. i+ +) loop2: for(int j=0.x+ +.

21. 7. 33. 42. & F C B . 50. True/False Questions B A A B A A A B A B B B 4. 24. D. 25. 39. 40. 55. 36. B. 45. 56. D. 22. 37. } } } What will be the output? 45. E & F A. 18. 26. 59. 11. 24. 27. 43. 20. 16. 49. 13. D & E B 3. A A B B B B A B B A B B 2. 37. 23. } finally { System. 51. 22. 25. 29. 41. B&D C D A&C D A. 30. 28. C & E C B. } catch(Exception e) { System. 7. 28. 50. B B A B B B B A B B A B Multiple-choice Questions 3. 9. 12. 60. D. D B C&E A C C A. 46. 33. 19. 52. 57. & E C 4. C C D&E B C D A&C B&C B&C A. 55. C & D C D A. 16. D & E E B. 41. 59. 38. 51. 30. 58. Write a statement that would construct a 20 point bold Helvetica font. return. 34. B A B A B B B A A B A B Part B: 1.424 Programming with Java: A Primer throw(new Exception(“Thrown”)). 35. return. 42. 58. 20. 35. 23.out. D&E A. 53. 19. & E C B C B. 8. 12. A B B A B A A B B A B A 5. 10. 48. 52. 47. 29. 10. 21. 17. 31. D & E D B&C B. C & D C 5. 8. B.println(“Exception caught”). 48. 45. 39. 6. 11. 54. & C B&C E B C&D D B. 17. D & E 2. C. 54. 40. 26. 14. 14.println(“finally”). 15. 18. 13. 32. 44. 46. 43. 15. 60. 9. 53. 49. 44. 47. 36. 56.out. E & F A. 38. 6. 27. 34. 57. 32. C. C C B C&B A B D B. ANSWERS Part A: 1. 31.

69. C & E 61. C & D 64. Infinite loop import EDU. 39. 42. 79. C D D C A. 67.0 RandomAccessFile class is wonderful Begin 30 m + n = 40. 7. C & E A. 17. 81.20). 76. 11. 45. D & E B A&C 62. 78. 66. 30. x = 10 drawRoundRect (10. 19. 72. 77. 21.100. 84. No. abstract No. 33. 70. 10. 35. 14.seek(raf. 75. B. 12. 27.Student. 43. 18. C & E A&C E C A&C 63. 29. 5. 28. 44. The package definition must come first No.200. 37. E & F D C Part C: Short answer Questions 1. 23. The static method trying to invoke a non-static method x = 10. B. 85. 3. 71. B&E D D B. 22. 26. 73. 83.40). E C A. 68. 32. 24. D C B. 8. 4.BOLD. 200 null (i = 10) is the problem a is 5 m is 0 retrun (x = = y)? x+y : 0. 82. 25. D. 31. is unreachable six : 33 s= 10 No output No output. y = 20 Result is 14 File class raf.20. 16. 161 n = 40. Central Madras 10 No No Line 3 –263 to 263 –1 100 No new Font(“Monospaced”.10. 13. 38. Font.length(( ). 80. 15. 40. 34. 6. 36. 0 x = x < 0? – x :x. StringBuffer 11 No Exception caught finally . 9. 74. 2. The field age in the Employee class should be public RandomAccessFile class Result = 3.Test.Appendix K: SCJP Exam Model Questions 425 65. 41. 20.

Sign up to vote on this title
UsefulNot useful