Principalsofprogramminglanguagesse.files.wordpress.com



1. The class at the top of exception class hierarchy is ................. A. ArithmeticExceptionB. ThrowableC. ObjectD. ExceptionAnswer : B2. When does Exceptions in Java arises in code sequence?a) Run Timeb) Compilation Timec) Can Occur Any Timed) None of the mentionedAnswer : a3. Which of these keywords is not a part of exception handling?a) tryb) finallyc) thrownd) catchAnswer : c4. Which of these keywords must be used to monitor for exceptions?a) tryb) finallyc) throwd) catchAnswer : a5. Which of these keywords must be used to handle the exception thrown by try block in some rational manner?a) tryb) finallyc) throwd) catchAnswer : d6. Which of these keywords is used to manually throw an exception?a) tryb) finallyc) throwd) catchAnswer : c7. What is the output of this program? class exception_handling { public static void main(String args[]) { try { System.out.print("Hello" + " " + 1 / 0); } catch(ArithmeticException e) { System.out.print("World"); } } }a) Hellob) Worldc) HelloWorldd) Hello WorldAnswer : b8. Which exception is thrown when divide by zero statement executes?A. NumberFormatExceptionB. ArithmeticExceptionC. NullPointerExceptionD. None of theseAnswer : B9. What happen in case of multiple catch blocks?A. Either super or subclass can be caught first.B. The superclass exception must be caught first.C. The superclass exception cannot caught first.D. None of theseAnswer : C10. Which exception is thrown when an array element is accessed beyond the array size?A. ArrayElementOutOfBoundsB. ArrayIndexOutOfBoundsExceptionC. ArrayIndexOutOfBoundsD. None of theseAnswer : B11. Predict the output of following Java programclass Main { public static void main(String args[]) { try { throw 10; } catch(int e) { System.out.println("Got the Exception " + e); } }}A. Got the Exception 10B. Got the Exception 0C. Compiler ErrorD. All statements are correct.Answer : C12. The exception class is in ____ package A. java.fileB. java.ioC. java.langD. java.utilAnswer : C13. Which of these stream contains the classes which can work on character stream?a) InputStreamb) OutputStreamc) Character Streamd) All of the mentionedAnswer : c14. Which of these class is used to read characters in a file?a) FileReaderb) FileWriterc) FileInputStreamd) InputStreamReaderAnswer : a15. Which of these method of FileReader class is used to read characters from a file?a) read()b) scanf()c) get()d) getInteger()Answer : a16. Which of these class can be used to implement input stream that uses a character array as the source?a) BufferedReaderb) FileReaderc) CharArrayReaderd) FileArrayReaderAnswer : c17. Which of these is a method to clear all the data present in output buffers?a) clear()b) flush()c) fflush()d) close()Answer : b18. Which of these classes can return more than one character to be returned to input stream?a) BufferedReaderb) Bufferedwriterc) PushbachReaderd) CharArrayReaderAnswer: c19. What is the output of this program? import java.io.*; class filesinputoutput { public static void main(String args[]) { InputStream obj = new FileInputStream("inputoutput.java"); System.out.print(obj.available()); } }Note: inputoutput.java is stored in the disk.a) trueb) falsec) prints number of bytes in filed) prints number of characters in the fileAnswer: c20. What is the output of this program? import java.io.*; class Chararrayinput { public static void main(String[] args) { String obj = "abcdefgh"; int length = obj.length(); char c[] = new char[length]; obj.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 1, 4); int i; int j; try { while ((i = input1.read()) == (j = input2.read())) { System.out.print((char)i); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }a) abcb) abcdc) abcded) None of the mentionedAnswer: d21. Which of these is a type of stream in Java?a) Integer streamb) Short streamc) Byte streamd) Long streamAnswer: c22. Which of these classes are used by Byte streams for input and output operation?a) InputStreamb) InputOutputStreamc) Readerd) All of the mentionedAnswer: a23.Which of these is used to perform all input & output operations in Java?a) streamsb) Variablesc) classesd) MethodsAnswer : a24. Which of these classes are used by character streams for input and output operations?a) InputStreamb) Writerc) ReadStreamd) InputOutputStreamAnswer: b25. Which of these class is used to read from byte array?a) InputStreamb) BufferedInputStreamc) ArrayInputStreamd) ByteArrayInputStreamAnswer : d26. What is the output of this program? class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); StringBuffer s2 = s1.reverse(); System.out.println(s2); } }a) Hellob) olleHc) HelloolleHd) olleHHelloAnswer : b27. Can data flow through a given stream in both directions?a. No; a stream has one direction only, input or outputb. No; streams only work for outputc. Yes; only one stream is needed to read and write a filed. Yes; but only one direction at a timeAnswer : a28. What is the name of a stream that connects two running programs?a. Program streamb. Conduitc. Piped. Channel Answer : c 29. Which of these constructors is used to create an empty String object?a. String()b. String(void)c. String(0)d. None of the mentionedAnswer : a30. Which of these is an oncorrect statement?a. String objects are immutable, they cannot be changed.b. String object can point to some other reference of String variable.c. StringBuffer class is used to store string in a buffer for later use.d. None of the mentionedAnswer : c31. What is the output of this program? class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); String s1 = "abcd"; int len1 = s1.length(); int len2 = s.length(); System.out.println(len1 + " " + len2); } }a) 3 0b) 0 3c) 3 4d) 4 3Answer: d32. Which of these method of class String is used to obtain length of String object?a. get()b. Sizeof()c. lengthof()d. length()Answer: d33. Which of these method of class String is used to extract a substring from a String object?a. substring()b. Substring()c. SubString()d. None of the mentionedAnswer: a34. What will s2 contain after following lines of code?String s1 = “one”;String s2 = s1.concat(“two”)a. oneb. twoc. onetwod. twooneAnswer: c35. What is the value returned by function compareTo() if the invoking string is less than the string compared?a. zerob. value less than zeroc. value greater than zerod. None of the mentionedAnswer: b36. Which of the following statement is correct?a. replace() method replaces all occurrences of one character in invoking string with another character.b. replace() method replaces only first occurances of a character in invoking string with another character.c. replace() method replaces all the characters in invoking string with another character.d. replace() replace() method replaces last occurrence of a character in invoking string with another character.Answer: a37. What is the output of this program? class output { public static void main(String args[]) { String s = "Hello World"; int i = s.indexOf('o'); int j = s.lastIndexOf('l'); System.out.print(i + " " + j); } }a. 4 8b. 5 9c. 4 9d. 5 8Answer: c38. boolean result = true;Which type of literal is assigned to the variable "result" ?A. stringB. booleanC. boolD. charAnswer: B39. Which type of literal is written in pair of single quote ?A. IntegerB. BooleanC. FloatD. CharacterAnswer: D40. An integer literal is of type long if and only if it has suffix - __________ in Java Programming.A. FB. LC. OD. DAnswer: B ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download