0% found this document useful (0 votes)
50 views2 pages

Sadrzi Samo 1 Polje Korisnik - Ime I 1 Korisnik - Id!

The document discusses Java classes and objects. It provides examples of a Korisnik class with static and non-static fields, a Student class with fields like name and id and a method to calculate average test score, and a KockaZaIgru class to represent a dice with a field to store the number and a method to roll it. It also demonstrates creating objects from a class and accessing fields and methods of the object.

Uploaded by

chedica223401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views2 pages

Sadrzi Samo 1 Polje Korisnik - Ime I 1 Korisnik - Id!

The document discusses Java classes and objects. It provides examples of a Korisnik class with static and non-static fields, a Student class with fields like name and id and a method to calculate average test score, and a KockaZaIgru class to represent a dice with a field to store the number and a method to roll it. It also demonstrates creating objects from a class and accessing fields and methods of the object.

Uploaded by

chedica223401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Sadrzi samo 1 polje Korisnik.ime i 1 Korisnik.id!

class Korisnik {
static String ime;
static int id;
}

sablon za vise promenljivih


class Korisnik {
String ime;
int id;
static String prezime; //​Moze mesano, jer svi imaju isto prezime
}

STUDENT
public class Student {
public String ime;
public int id;
public double test1, test2, test3;

public double prosek () {


return (test1 + test2 + test3) / 3;
}
}
u javi nijedna promenljiva ne sadrzi neki objekat
STUDENT
public class Student {
public String ime;
public int id;
public double test1, test2,test3;

public double prosek() {


return (test1+test2+test3) / 3;
}
}

s = new Student();
System.out.print (“Prosecna ocena studenta “+s.ime);
System.out.print (s.prosek());

Bez obzira sto je s konstanta, polja se menjaju jer s samo ukazuje na njih
final Student s=new Student();
s.ime = “Jenigga!”

KOCKAAAA
public class KockaZaIgru{
public int broj = (int)(6*Math.random()) +1;
public void baci() {
broj= (int) (6*Math.random()) +1
}
}

KockaZaIgru kocka;​ //Deklaracija promenljive


kocka = new KockaZaIgru();​ // objekat kocka klase KockaZaIgru
ili KockaZaIgru kocka = new KockaZaIgru();

You might also like