Page 100 - CA_Blue( J )_Class10
P. 100
6. What are the various types of errors in Java? [2019]
Ans. The three types of errors are compile-time error, runtime error and logical error.
7. Write the output for the following:
String s1 = "phoenix";
String s2 = "island";
System.out.println(s1.substring(0).concat(s2.substring(2)));
System.out.println(s2.toUpperCase()); [2019]
Ans. The output is:
phoenixland
ISLAND
8. System.out.print("BEST");
System.out.println("OF LUCK");
Choose the correct option for the output of the above statements:
a. BEST OF LUCK b. BEST
OF LUCK [2018]
Ans. The output is:
BEST OF LUCK
9. Write the output for the following:
System.out.println("Incredible" + "\n" + "world"); [2018]
Ans. The output is:
Incredible
world
10. Give the output of the following string functions:
a. "ACHIEVEMENT".replace('E', 'A')
b. "DEDICATE".compareTo("DEVOTE") [2018]
Ans. a. ACHIAVAMANT b. -18
11. What is the difference between the Scanner class’s functions next() and nextLine()? [2017]
Ans.
next() nextLine()
Used to input a single word. Used to input a sentence containing at least two words.
Example: String w= sc.next(); Example: String s=sc.nextLine();
12. What is the function of catch block in exception handling? Where does it appear in a program? [2015]
Ans. If any exception has occurred in a program, then the catch block handles it. It appears just below after the try block.
13. Which of the following is a valid comment? [2014]
a. /*comment */ b. /*comment
c. /comment d. */comment*/
Ans. a. /*comment*/
14. What is an exception? [2013]
Ans. An exception is a situation in which the execution of a program stops abnormally.
15. Name the methods of Scanner class that:
a. is used to input integer data from the standard input stream.
b. is used to input a String data from the standard input stream.
Ans. a. nextInt() b. next() or nextLine()
16. Name the type of error (syntax, runtime or logical error) in each case given below: [2012]
a. Division by a variable that contains a value of zero.
b. Multiplication operator is used when the operation should be division.
c. Missing semicolon.
Ans. a. Runtime Error b. Logical Error c. Syntax error
9898 Touchpad Computer Applications-X

