Vous êtes sur la page 1sur 11

1.

Given :
public class Sequence {
Sequence() { System.out.print(“c “); }
{ System.out.print(“y “); }
public static void main(String[] args) {
new Sequence().go();
}
void go() { System.out.print(“g “); }
static { System.out.print(“x “); }
}
What is the result?
A) c x y g
B) c g x y
C) x c y g
D) x y c g
E) y x c g
F) y c g x

2. Given:
public class MyStuff {
MyStuff(String n) { name = n; }
String name;
public static void main(String[] args) {
MyStuff m1 = new MyStuff(“guitar”);
MyStuff m2 = new MyStuff(“tv”);
System.out.println(m2.equals(m1));
}
public boolean equals(Object o) {
MyStuff m = (MyStuff) o;
if(m.name != null)
return true;
return false;
}
}
What is the result?
A) The output is “true” and MyStuff fulfills the Object.equals() contract.
B) The output is “false” and MyStuff fulfills the Object.equals() contract.
C) The output is “true” and MyStuff does NOT fulfill the Object.equals() contract.
D) The output is “false” and MyStuff does NOT fulfill the Object.equals() contract
E) Compilation fails
3. Given:
import java.util.*;
public class Primes {
public static void main(String[] args) {
List p = new ArrayList();
p.add(7);
p.add(2);
p.add(5);
p.add(2);
p.sort();
System.out.println(p);
}
}
What is the result?
A) [2, 5, 7]
B) [2, 2, 5, 7]
C) [7, 2, 5, 2]
D) [7, 5, 2, 2]
E) Compilation fails

4. Given:
public class MyLoop {
public static void main(String[] args) {
String[] sa = {“tom “, “jerry “};
for(int x = 0; x < 3; x++) {
for(String s: sa) {
System.out.print(x + ” ” + s);
if( x == 1) break;
}
}
}
}
What is the result?
A) 0 tom 0 jerry 1 tom
B) 0 tom 0 jerry 1 tom 1 jerry
C) 0 tom 0 jerry 2 tom 2 jerry
D) 0 tom 0 jerry 1 tom 2 tom 2 jerry
E) 0 tom 0 jerry 1 tom 1 jerry 2 tom 2 jerry
F) Compilation fails.
5. Apa output dari kode program berikut?
interface Rideable f String getGait() ; )
public class Camel implements Rideable t
int weight = 2;
String getGait() ( return " mph, lope"; )
void go (int speed) (
++speed; weight++;
int walkrate = speed * weight; System.out.print (walkrate + getGait ()) ;
public static void main(String[ ] args) [
new Camel () .go (8) ;
Select one:
a. Kompilasi berhasil tetapi eksekusi gagal
b. 27 mph, lope
c. 16 mph, lope
d. Kompilasi Gagal karena hak akses
e. 24 mph, lope

6. Given:
class Alpha {
String getType() { return “alpha”; }
}
class Beta extends Alpha {
String getType() { return “beta”; }
}
class Gamma extends Beta {
String getType() { return “gamma”; }
public static void main(String[] args) {
Gamma g1 = new Alpha();
Gamma g2 = new Beta();
System.out.println(g1.getType() + ” ”
+ g2.getType());
}
}
What is the result?
A) alpha beta
B) beta beta
C) gamma gamma
D) alpha alpha
E) Compilation fails.
7. Given:
class Feline {
public String type = “f “;
public Feline() {
System.out.print(“feline “);
}
}
public class Cougar extends Feline {
public Cougar() {
System.out.print(“cougar “);
}
public static void main(String[] args) {
new Cougar().go();
}
void go() {
type = “c “;
System.out.print(this.type + super.type);
}
}
What is the result?
A) cougar c c
B) cougar c f
C) feline cougar c c
D) feline cougar c f
E) Compilation fails
F) An exception is thrown at run time.

8. Given:
public class Calculator {
int num = 100;
public void calc(int num) {
this.num = num * 10;
}
public void printNum() {
System.out.println(num);
}
public static void main(String[] args) {
Calculator obj = new Calculator();
obj.calc(2);
obj.printNum();
}
}
What is the result?
A) 20
B) 100
C) 1000
D) 2

9. Given:
import java.util.*;
public class App {
public static void main(String[] args) {
List p = new ArrayList();
p.add(7);
p.add(1);
p.add(5);
p.add(1);
p.remove(1);
System.out.println(p);
}
}
What is the result?
A) [7, 1, 5, 1]
B) [7, 5, 1]
C) [7, 5]
D) [7, 1]

10. Pernyataan berikut yang tidak ada pada konsep pemrograman Java adalah
A. Encapsulation
B. Polymorphisme
C. Single Inheritance
D. Multiple Inheritance
E. Multi Level Inheritance

11. Berikut adalah penamaan atribut pada java yang diperbolehkan, kecuali...
A._Nama
B. Nama_Peg
C. $Nama
D. 1Nama
E. Jawaban A, B, C, dan D salah
12. Pernyataan berikut yang salah tentang abstract classes pada Java adalah
A. Jika kita turunkan abstract class dan tidak mengimplementasikan semua abstract methods, maka
derived class harus ditandai dengan kata kunci 'abstract’ kata eko
B. Abstract classes dapat memiliki constructors. bisa jadi
C. Sebuah class dapat dibuat abstract tanpa ada abstract method
D. Sebuah class dapat diturunkan dari multiple abstract classes
E. Sebuah abstract class dapat memiliki beberapa abstract method

13. Konsep penyederhanaan dari sesuatu yang kompleks dengan cara memodelkan kelas sesuai dengan
masalahnya adalah......
A. Properties
B. Enkapsulasi
C. Inheritance
D. Polymorphism
E. Abstraksi

14. Apa hasil output dari kode program berikut?


public class Aljabar {
int tambah(int m, int n)( return m+n;)
int kali(int m, int n)( int hsl=0;
for (int i=1;i<=n;i++) hsl+=tambah(m,m);
return hsl;
}
}
public class UjiAljabar extends Aljabar{
public static void main(String args[] ){
short angka = 8;
System.out.printin(kali (s.4));
}
A. Kesalahan saat compile pada baris 11
B.Kesalahan saat compile pada baris 9~
C.32
D.12
E. 11

15. Apa output dari kode program berikut?


public class Kartu f
int hati;
static int wajik;
boolean istrue;
public void cetak() [
System.out.print(wajik);
System.out.print(istrue); misal (!istrue)
System.out.print(hati);
public class UjiKartul
public static void main(String argv[ ]X
Kartu remi = new Kartu);
remi.cetak();
A.Ofalse0
B.Otrue0
C.000
D.Kompilasi error.
E.Kompilasi berhasil tetapi eksekusi gagal

16. Berikut ini adalah class atau interface yang termasuk dalam Java collection framework, kecuali
A Set
B. ArrayDeque
C. List
D. Map
E.TreeList

17. import java util. *:


public class TestMap {
public static void main(String [] args){
String [] words = new String[] {"aaa, "bbb" "ccc" "aaa"};
Map<String, Integer m = new TreeMap<String, Integer> ();
for (String word : words) {
TYPE freq = m.get(word);
m.put(word, (freq == null) ? 1: freq + 1);
) System out. println(m);
Ubah kata TYPE dengan jawaban yang tepat dibawah ini
A. int
B. String
C. Integer
D. Byte
E. Jawaban A, B, C, dan D salah

18. Interface yang dapat digunakan untuk mengurutkan Map menggunakan ...
A. SortedMap
B. LinkedMap
C. HashMap
D. Mapping
E. TreeMap
19. Cara pendeklarasian Class Generics yang benar adalah?
A ditandai dengan simbol yang diawali oleh '<' dan ditutup oleh 'v' setelah nama method
Yang bener sih ditandai dengan simbol yang diawali oleh '<' dan ditutup oleh '>' setelah nama
class
B. ditandai dengan simbol yang diawali oleh '<' dan ditutup oleh 'v' sebelum nama class
C. ditandai dengan simbol yang diawali oleh '<' dan ditutup oleh 'v' sebelum nama method
D. ditandai dengan simbol yang diawali oleh '<' dan ditutup oleh '_' sebelum void
E, ditandai dengan simbol yang diawali oleh '<' dan ditutup oleh 'v' setelah void

20. Apa output dari kode program berikut?


1. public class Test {
2. public static void main(String... args) {
3. Integer i = 34;
4. String str=(i<21)?"jan":(i<56)?"feb":"mar";
5. System.out.printin(str);
6. }
7. }
A. mar
B. jan
C. feb
D. Kompilasi gagal pada baris
E. Kompilasi gagal pada baris 5 itu kalo bukan println kalo println hasilnya feb

21. Apa output dari kode program berikut ?


public class UjiEnum I
enum Month I JAN, FEB, MAR ;
public static void main(String... args) [
Month m1 = Month. JAN;
Month m2 = Month. JAN;
Month m3 = Month. FEB;
System.out.println (m1 == m2) ;
system.out.println (m1.equals (m2)) ;
System.out.println (m1 == m3) ;
System.out .println (m1.equals (m3)) ;
Select one:
a. falsetruefalsetrue
b. falsetruefalsefalse
c. truetruefalsetrue
d. truetruefalsefalse
e. Instantiated Error

22. Apa output dari kode program berikut?


import java.io.File;
public class UjiTxt (
public static void main(String[ ] args) throws Exception [
File file = new File("test.txt") ;
System.out .print (file.exists () ) ;
System.out.print (" ") ;
file.createNewFile () ;
system.out .print (file.exists () ) ;
Select one:
a. Jawaban A, B, C, dan D salah
b. true false
c. false false
d. true true
e. false true

23. Apa output dari kode program berikut?


import java.util.Iterator;
import java.util.TreeSet;
public class UjiCollection f
public static void main(String... args) !
TreeSet s1 = new TreeSet () ;
s1.add("satu") ; sl.add("dua"); s1.add("satu"); s1.add("tiga") ;
Iterator it = sl.iterator () ;
while (it.hasNext () ) (
System.out.print( it.next() +"" );
Select one:
a. satu dua tiga
b. Jawaban A,B, C,dan D Salah
c. Runtime Exception
d. dua satu tiga
e. satu dua satu tiga

24. Apa output dari kode program berikut?


public class UjiTambah f
static int i =5;
public static void main(String... args) {
System.out.print(i++ +" ");
System.out.printli t" ");
System.out.print(++i +" ");
System.out.print(++i+i+++" ");
Select one:
a. 56716
b. 55716
c. 56616
d. 66616
e. 66716

25. Apa output dari kode program berikut?


public class UjiVariabel{
int _$; int $3; int do;
public static void main(String argvl[]X
UjiVariabel latihan = new UjiVariabel();
latihan.$3=3;
latihan.do=9;
System.out.print(latihan.$3);
System.out.print(latihan.do);
System.out.print(latihan._S);
Select one:
a. 790
b. Kompilasi gagal - $3 bukan identifier yang valid.
c. 700
d. Kompilasi gagal - _$ bukan identifier yang valid.
e. Kompilasi gagal - do bukan identifier yang valid.

Collection class yang dapat diperbesar dan diperkecil ukurannya dan menyediakan akses index ke
elemennya, tetapi tidak bersifat synchronized, adalah ARRAYLIST

Suatu blueprint atau cetakan untuk menciptakan suatu instant dari object adalah konsep CLASS

class Parent
{
private void method1()
{
System.out.println("Parent's method1()");
}
public void method2()
{
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent
{
public void method1()
{
System.out.println("Child's method1()");
}
public static void main(String args[])
{
Parent p = new Child();
p.method2();
}
}

Parent's method2()
Parent's method1()

Vous aimerez peut-être aussi