7411030850 B
1. Which are valid declarations? A. int $x; B. int 123 C. int _123; D. int #dim; E. int %percent; F. int *devide; G. int central_sales_region_Summer_2005_gross_sales; Jawaban : A, C, dan G Alasan : karena identifiers harus Diawali dengan huruf yang unik, underscors (_) atau tanda dollar ($) dan tidak boleh dimulai dengan angka Tidak menggunkan keyword java
2. Which of the following are invalid variable name in java? A. $char B. 1MyNumber C. case D. _int Jawaban : A dan D Alasan : karena jawaban B dan C melanggar aturan nama identifier jawaban B melanggar aturan penamaan dengan menggunakan angka sebagai huruf awal jawaban C melanggar aturan penaman dengan menggunakan keyword java jawaban A dan D walaupun menggunakan (int dan char) keyword java tetapi diawali dengan [$] tanda dollar dan (_) underscors maka kata kata itu dikenali sebagai identifier 3. Consider the following line of code : short ohMy What is the range of values that could be assigned to the variable ohMy? A. 0 to 216 1 B. 0 to 215 1 C. -215 1 to 215 1 D. -216 1 to 216 1 E. -215 to 215 1 F. -215 to 215
5. Consider the following line of code : byte ohMy What is the range of values that could be assigned to the variable ohMy? A. 0 to 216 1 B. 0 to 28 1 C. -27 to 27 1 D. -27 to 27 E. -215 to 215 1 F. -28 to 28 1
6. Which of the following statements would not produce the compile error? A. char my_char = c; B. char your_char = int; C. char what =Hello; D. chat what_char = L E. char ok =\u3456; int dan Hello dianggap sebagai literal sehingga tidak diizinkan untuk di Compile L melanggar aturan penulisan [diawali dan diakhiri dengan single quote ( )] c sesuai dengan aturan [diawali dan diakhiri dengan single quote ( )] \u3456 medeklarasikan karakter dengan unique code dengan dialawi \u
8. Consider the following piece of code: public class No8{ public static void main (String [] args){ float luckyNumber = 1.25; System.out.println ("The Value of LuckyNumber : " + luckyNumber); }} What is the result? A. The value of luckyNumber::. B. The value of luckyNumber: 1.25. C. This piece of code would not compile. D. This piece of code would compile, but give an error at execution time. Trjadi kesalahn pada pendeklarasian float lucky Number =1.25 seharusnya float lucky Number =1.25f karena default dari pendeklarasian awal adalah double sedangkan untuk yang lucky Number =1.25f datanya beubah menjadi tipe float
9. Given: class Scoop { static int thrower() throws Exception { return 42; } public static void main(String [] args) { try { int x = thrower(); } catch (Exception e) { x++; } finally { System.out.printIn("x = " + ++x); } } } What is the result? A. x = 42 B. x = 43 C. x = 44 D. Compilation fails. E. The code runs with no output
11. In the following code fragment, what are the legal data types for the variable answer? byte b = 1; char c = 2; short s = 3; int i = 4; float f = 5f; answer = b*c*s*i*f; A. byte B. char C. short D. int E. float F. double G. long
13. Whice of the following lines of code are valid java statements? (Choose all that apply) A. byte b = 5; B. byte b = 5L; C. float f = 123; D. float f = 123.4; E. short s = -1; menambahkan l/L hany untuk type data long untuk tipe data float menambahkan f/F untuk tipe data float menambahkan f/F harus Positif
14. Which of the following lines of code are valid java statements? (Choose all that apply) A. short s = 11; B. short s = 11L; C. float f = 432; D. float f = 432.1; E. byte b = -1; tambahan l/L hanya untuk type data long untuk float harus menambahkan F/f untuk float harus menambahkan F/f
15. What is the result of attemting to compile and execute the following choose all application? class q { public static void main(String[] args){ byte b1 = -5; byte b2 = -b1; System.out.println("b2 = " + b2); } }
16. Jika di kompile program ini terdapat error. Betulkan kesalahannya dan beri penjelasan !
Hal ini terjadi karena type data short lebih kecil dibandingkan dengan double sehingga tidak dapat dikonversi berhubung kedua data trsebut adalah type data Non Boolean maka dapat diatasi dengan widening conversion Solusi dengan cara menambahkan casting (short) seperti berikut : s = (short) d;
17. Jika di kompile program ini terdapat error. Betulkan kesalahannya dan beri penjelasan!