Download presentation
Presentation is loading. Please wait.
Published byDavis Beverley Modified over 9 years ago
1
Discussion1 Quiz
2
Q1 Which of the following are invalid Java identifiers (variable names)? a) if b) n4m3 c) Java d) 12345 e) DEFAULT_VALUE f) bad-choice g) 1two3 h) first name i) last.name
3
A1 Which of the following are invalid Java identifiers (variable names)? a) if b) n4m3 c) Java d) 12345 e) DEFAULT_VALUE f) bad-choice g) 1two3 h) first name i) last.name
4
Q2 Which of these identifiers violate the naming convention for object names? a) R2D2 b) isthisokay? c) Java d) 3CPO e) ThisIsReallyOkay f) Java g) anotherbadone
5
A2 Which of these identifiers violate the naming convention for object names? a) R2D2 b) isthisokay? c) Java d) 3CPO e) ThisIsReallyOkay f) Java g) anotherbadone
6
Q3 What is the output of the following statements a) System.out.println( (a++)++ ); b) System.out.println( 2.5 == 5 / 2 ); c) System.out.println( 2.0 + 3/2 ); d) System.out.println( 5 % 3); e) System.out.println(5 + 4/2.0); f) float f = 1.1; System.out.println(f – 0.1); g) int a = 10; System.out.println(a = 11);
7
A3 What is the output of the following statements a) System.out.println( (a++)++ ); //error! b) System.out.println( 2.5 == 5 / 2 ); //false c) System.out.println( 2.0 + 3/2 ); //3.0 d) System.out.println( 5 % 3); //2 e) System.out.println(5 + 4/2.0); // 7.0 f) float f = 1.1; System.out.println(f – 0.1); //error! g) int a = 10; System.out.println(a = 11); //11
8
Q4 What is the result? boolean b1 = true; Boolean b2 = false; System.out.println(b1 || b2 = true); System.out.println(b1); System.out.println(b2);
9
A4 What is the result? boolean b1 = true; Boolean b2 = false; System.out.println(b1 || b2 = true); //b1 || b2 is evaluated first before = System.out.println(b1); System.out.println(b2);
10
Q5 What is the result? boolean b1 = true; Boolean b2 = false; System.out.println(b1 || (b2 = true)); System.out.println(b1); System.out.println(b2);
11
A5 What is the result? boolean b1 = true; Boolean b2 = false; System.out.println(b1 || (b2 = true)); //true System.out.println(b1); //true System.out.println(b2); //false
12
Q6 What is the result? boolean b1 = true; Boolean b2 = false; System.out.println(b1 && (b2 = true)); System.out.println(b1); System.out.println(b2);
13
A6 What is the result? boolean b1 = true; Boolean b2 = false; System.out.println(b1 && (b2 = true)); //true System.out.println(b1); //true System.out.println(b2); //true
14
Q7 What’s the output? String s1 = new String("John"); String s2 = new String("John"); if (s1 == s2) System.out.println("s1 == s2 is true"); else System.out.println("s1 == s2 is false");
15
A7 What’s the output? String s1 = new String("John"); String s2 = new String("John"); if (s1 == s2) System.out.println("s1 == s2 is true"); else System.out.println("s1 == s2 is false"); // s1 == s2 is false
16
Q8 Is there any problem with this? int a = 10; double b = 1.0; a = a + b; System.out.println(a);
17
A8 Is there any problem with this? int a = 10; double b = 1.0; a = a + b; //type error System.out.println(a);
18
Q8 Is there any problem with this? int a = 10; double b = 1.0; a += b; System.out.println(a);
19
A8 Is there any problem with this? int a = 10; double b = 1.0; a += b; System.out.println(a); //no problem! lhs op= rhs is actually lhs op= (type of lhs)rhs
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.