ZADANIE 1: Podaj wynik działania poniższego programu.
class Value{
public int i = 15;
}
public class Test{
public void first(){
int i = 5;
Value v = new Value();
v.i = 25;
second(v, i);
System.out.println(v.i);
}
public void second(Value v, int i){
i = 0;
v.i = 20;
Value val = new Value();
v = val;
System.out.println(v.i + " " + i);
}
public static void main(String args[]){
Test t = new Test();
t.first();
}
}
ODPOWIEDŹ: ...................................................................................................................................
ZADANIE 2: Podaj wynik działania poniższego programu.
public class A{
private void metoda1() throws Exception{
throw new RuntimeException();
}
public void metoda2(){
try{
metoda1();
}
catch(RuntimeException e){
System.out.println("Caught Runtime Exception");
}
catch(Exception e){
System.out.println("Caught Exception");
}
}
public static void main(String args[]){
A a = new A();
a.metoda2();
}
}
ODPOWIEDŹ: ...................................................................................................................................
ZADANIE 3: Podaj wynik działania poniższego programu.
class ListManager{
public void expandList(MyList l){
l.size = l.size + 10;
}
}
public class MyList{
int size = 1;
public static void main (String[] args){
MyList list = new MyList();
list.size = 10;
ListManager lm = new ListManager();
lm.expandList(list);
System.out.println("list.size = " + list.size);
}
}
ODPOWIEDŹ: ...................................................................................................................................
ZADANIE 4: Podaj wynik działania poniższego programu.
interface Test{
public int a = 34;
public void add();
public String msg();
}
abstract class T1 implements Test{
int m = 340;
int a = 23;
abstract public void add();
public String msg(){
return "Class T1" + " " + a;
}
}
class T2 extends T1{
int k = 124;
public void add(){
k = k + a;
System.out.println("k: " + k);
}
public String msg(){
return"Class T2" + " " + super.msg() + " " + Test.a + " " + m;
}
}
class T3 {
public static void main(String[] args){
Test ob = new T2();
ob.add();
System.out.println(ob.msg());
}
}
ODPOWIEDŹ: ...................................................................................................................................