0% found this document useful (0 votes)
89 views6 pages

Java Practice Sheet for Grade 9 ICSE

The document is a practice sheet for Grade 9 ICSE students focusing on Java programming concepts. It contains multiple choice questions and debugging exercises that cover topics such as data types, output formatting, Unicode, and variable initialization. The sheet aims to reinforce students' understanding of Java syntax and functionality through practical examples.

Uploaded by

Nive Droid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views6 pages

Java Practice Sheet for Grade 9 ICSE

The document is a practice sheet for Grade 9 ICSE students focusing on Java programming concepts. It contains multiple choice questions and debugging exercises that cover topics such as data types, output formatting, Unicode, and variable initialization. The sheet aims to reinforce students' understanding of Java syntax and functionality through practical examples.

Uploaded by

Nive Droid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Grade 9 ICSE – Java Application-Based Practice Sheet

Part A – Multiple Choice Questions (1 mark each)

1. Find the output.

char ch = 65;
[Link](ch + 1);

a) 66 b) B c) 65B d) AB

2. Which will correctly print Java\tRocks exactly as shown?


a) [Link]("Java\tRocks"); b) [Link]("Java\\tRocks");
c) [Link]('Java\tRocks'); d) [Link]("Java/tRocks");

3. What will happen?

final double PI = 3.14;


PI = 3.14159;

a) Changes value b) Runtime error c) Compile-time error d) Prints both values

4. Find the output.

[Link](5 + 5 + "5");

a) 55 b) 105 c) 155 d) Error

5. You want to store ASCII for 'M' in an int and print it. Which is correct?
a) int x = 'M'; [Link](x); b) int x = "M"; [Link](x); c) char x =
'M'; [Link]((int)M); d) int x = ASCII('M');

6. Debug:

char grade = "A";

a) No change b) Use single quotes c) Remove quotes d) Use int

7. Find the output.

char c = '\u0041';
c=c+1;
[Link](c);

a) A b) B c) C d) Error

8. Which will produce an error?


a) int x = 0x1A; b) int y = 010; c) int z = 08; d) double r = 2.5;
9. You want to print Hello\World. Which is correct?
a) [Link]("Hello\World"); b) [Link]("Hello\\World"); c)
[Link]('Hello\World'); d) [Link](Hello\\World);

10. Find the output.

int a = 5;
int b = a * 2;
[Link](b);

a) 5 b) 10 c) Error d) 0

11. Which initialization is dynamic?


a) int a = 10; b) int b = a * 5; c) final int x = 100; d) char c = 'C';

12. Find the output.

[Link]("Path: C:\\Java\\bin");

a) Path: C:\Java\bin b) Path: C:\Java\bin c) Path: C:Java\bin d) Error

13. You want to store Unicode Ω. Which is correct?


a) char omega = '\u03A9'; b) char omega = "u03A9"; c) char omega = '\u3A9'; d) char omega
= '\U03A9';

14. Find the output.

boolean flag = true;


[Link](!flag);

a) true b) false c) 0 d) 1

15. Debug:

int rate = 2.5f;

a) Use double b) Use float c) Use int with no decimal d) Use String

16. Find the output.

[Link]((char)90);

a) Y b) Z c) X d) [

17. Which will compile?


a) char c = 'AB'; b) char c = 'A'; c) char c = "A"; d) char c = 65.0;

18. Find the output.

[Link]("A\tB\tC");

a) A B C b) A B C c) A_B_C d) Error
19. Which will print ASCII of lowercase 'm'?
a) (int) 'm' b) 'm' c) ascii('m') d) (char) 'm'

20. Find the output.

[Link](2 + 2 + "2");

a) 222 b) 42 c) 22 d) 4

21. Debug:

String name = 'Java';

a) Use double quotes b) Use single quotes c) Use int d) Remove quotes

22. Find the output.

char ch = 97;
[Link](ch);

a) a b) 97 c) A d) Error

23. Which will cause compile-time error?


a) final int x = 5; x = 6; b) int y = 5; y = 6; c) int z; z = 10; d) double d = 3.5;

24. Find the output.

[Link]("Hello\nWorld");

a) Hello World b) Hello


World c) Hello\World d) Error

25. Debug:

int num = "100";

a) No change b) Remove quotes c) Use String instead of int d) Add semicolon

26. Find the output.

char c = 65;
[Link]((int)(c + 25));

a) 65 b) 90 c) 91 d) Z

27. Which literal is octal?


a) 0x1A b) 010 c) 26 d) 1A

28. Find the output.

char ch = '\u0043';
[Link](ch);
a) B b) C c) A d) D

29. Which line stores float correctly?


a) float x = 2.5; b) float x = 2.5f; c) float x = "2.5"; d) float x = '2.5';

30. Find the output.

[Link](010 + 1);

a) 11 b) 9 c) 8 d) Error

31. Debug:

boolean done = "false";

a) Use false without quotes b) Use String type c) Use int d) Remove variable

32. Find the output.

[Link]("He said, \"Java is fun!\"");

a) He said, Java is fun! b) He said, "Java is fun!" c) He said, "Java is fun!" d) Error

33. Which will store the largest decimal value?


a) float b) double c) int d) long

34. Find the output.

[Link](0x1A + 5);

a) 31 b) 26 c) 21 d) 1A5

35. Find the output.:

int val = '\u0041';


[Link](val);

a) 65 b) A c) Error d) 41

36. Find the output.

char c = 'C';
c += 3;
[Link](c);

a) E b) F c) D d) H

37. Which separator encloses class definitions?


a) () b) {} c) [] d) <>

38. Find the output.

[Link]("Java" + 10 + 5);
a) Java105 b) Java15 c) Java 15 d) 105Java

39. Which is valid Unicode format?


a) \u0041 b) \U0041 c) u0041 d) "u0041"

40. Find the output.

char c = 65;
[Link](++c);

a) A b) B c) C d) D

Part B – Two-Mark Questions

1. Guess the output:

char ch = 'a';
[Link]((int) ch + 5);

2. Debug this code:

final int SPEED = 60;


SPEED = 80;

3. Write one Java statement to print C:\Programs\Java.

4. Guess the output:

[Link]("Value:\n10");

5. Write code to store the Unicode value for the Greek letter π in a char variable and display it.

6. Debug this code:

boolean status = "true";

7. Guess the output:

[Link](010 + 5);

8. Write Java code to print the ASCII value of uppercase ‘G’.

9. Debug this code:

char c = 'AB';

10. Guess the output:

char ch = '\u0044';
[Link](++ch);
11. Write Java code that dynamically initializes an integer to twice the value of 15 and prints it.

12. Debug this code:

float rate = 5.5;

13. Guess the output:

[Link]("Java" + (5 + 5));

14. Write Java code to store the octal literal 010 in an integer and print its decimal value.

15. Debug this code:

String symbol = '\u0041';

16. Guess the output:

char c = 65;
c = c+5;
[Link](c);

17. Write Java code to declare a final variable for gravity (9.8) and display it.

18. Debug this code:

char letter = "Z";

19. Guess the output:

[Link](5 + "5" + 5);

20. Write Java code to print the Unicode smiley face ☺ using \u notation.

Common questions

Powered by AI

The output will be '105', not '55'. In Java, during evaluation, if an expression involves a string after integer operations, integers are converted to strings and concatenated, resulting in '10' + '5' = '105'.

The output will be 'Java Rocks'. This is because the escape sequence '\t' is used to insert a tab between the words 'Java' and 'Rocks'.

The output of the expression will be 'Java105'. Java evaluates expressions from left to right, starting with "Java", all subsequent numerical operations are treated as string concatenations. Therefore, '10' is concatenated to 'Java', resulting in 'Java10', which is then concatenated with '5', resulting in 'Java105'.

To store and print the ASCII value of 'M', you declare an int variable as follows: 'int x = 'M';' and print it using 'System.out.println(x);'. This works because in Java, characters can be stored in integers directly resulting in their ASCII values being assigned.

The output will be '65'. The Unicode '\u0041' corresponds to 'A', which has the ASCII value of 65. Java evaluates the character to its corresponding integer value when assigned to an int type.

The error in the code is using double quotes instead of single quotes for the character 'A'. In Java, characters must be enclosed in single quotes to be correctly interpreted as the char data type, whereas double quotes are for strings.

The statement will result in a compile-time error because 'PI' is declared as a 'final' variable, and its value cannot be reassigned once initialized. The keyword 'final' in Java indicates that the variable's value is constant and cannot be changed.

'float x = 2.5f;' is correctly initializing the float variable. In Java, if a literal is of type float, it must be appended with 'f' or 'F' as it defaults to double.

The error occurs because 'false' is expected as a boolean literal, not a string. Java does not allow boolean variables to be initialized with strings. Removing the quotes will correct the code: 'boolean done = false;'.

The statement will give an error because the backslash '\' is a special escape character in Java that must be used in valid escape sequences like '\n' or '\t'. To print a single backslash, it must be escaped as double backslashes: 'System.out.println("Hello\\World");'.

You might also like