You are on page 1of 2

(04.03.

2013)

: ....................................................................
:
....................................................................
:
....................................................................
Zadatak, A B (file) Gzadatak.java.
)
class Zadatak {
( ). (0,5)
public static void main(String[] args) {
:
= new A();
a.m1a();
)
}
? (0,5)
1. }
:
class A {
void m1a() { System.out.println("metoda: m1a"); }
)
}
( ). (0,5)
class B {
:
void m1b() { System.out.println("metoda: m1b"); }
}
:
) main If2?
public class If2 {
(0,5)
static boolean b1, b2;
:
public static void main(String [] args) {
int x = 0;
if ( !b1 ) {
if ( !b2 ) {
) | || (.
b1 = true;
b1 | b2 b1 || b2). (0,5)
x++;
:
if ( 5 > 6 ) {
x++;
}
2.
if ( !b1 )
x = x + 10;
else if ( b2 = true )
x = x + 100;
else if ( b1 | b2 )
x = x + 1000;
}
}
System.out.println(x);
}
}
:
) main
public class BankarskiRacun {
BankarskiRacun? ? (0.5)
int stanje;
:
String imeKorisnika;
public BankarskiRacun (String imeKorisnika){
stanje = 10;
this.imeKorisnika = imeKorisnika;
)
}
. ,
public void vratiStanje(int stanje1){
. (1)
stanje1 = stanje;
3.
:
}
public static void main(String[] args) {
BankarskiRacun k = new BankarskiRacun
(Agrobanka);
int stanje1 = 0;
k.vratiStanje(stanje1);
System.out.println("Stanje je: "+stanje1);
}
}
().
. (1)
class SC2 {
public static void main(String [] args) {
SC2 s = new SC2();
4.
s.start();
}
String foo() {
return "foo";
}
1

(04.03.2013)
void start() {
int a = 3;
int b = 4;
System.out.print(" " + 7
System.out.print(a + b);
System.out.print(" " + a
System.out.print(foo() +
System.out.println(a + b
}
}
.
interface I1{}
class C1 implements I1{}
class C2 extends C1{}
class C3 extends C1{}
class C4 extends C1{}
class C5 extends C1{}

5.

6.

+ 2 + " ");

_____________________________________________________
_____________________________________________________
+ b + " "); _____________________________________________________
a + b + " "); _____________________________________________________
+ foo());
_____________________________________________________

a) .
. (1)
I1 i1;
__________________________________________________
C1 c1;
__________________________________________________
C3 c3 = new C3(); __________________________________________________
i1 = (I1) c3;
__________________________________________________
c1 = new C5();
__________________________________________________
c1 = i1;
__________________________________________________
i1 = c3;
__________________________________________________
) () ? . (0,5)
:

.
public class RTExcept {
public static void throwit () {
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args) {
try {
System.out.print("hello ");
throwit();
}
catch (Exception re) {
System.out.print("caught ");
}
// linija A
finally {
System.out.print("finally ");
}
System.out.println("after ");
}
}
.
package p1;
public class A{
int a;
}

) ()
main RTExcept? (0,5)
:

)
. (0,5)
:

) catch finally
( ) catch(IOException e) {...}?
? (0,5)
:

: (1)

B
C
D

package p2;
class B extends A{

class D extends A{

7.
class C{
A aObj;
}

8.

class E{
A aObj;
}

.
interface I { int x = 0; }
class T1 implements I { int x = 1; }
class T2 extends T1 { int x = 2; }
public class T3 extends T2 {
int x = 3;
void test() {
System.out.print(x);
System.out.print(super.x);
System.out.print(((T2) this).x);
System.out.print(((T1) this).x);
System.out.println(((I) this).x); }}

() ()
test()
3? (1)
:

You might also like