0% found this document useful (0 votes)
7 views

Java FD - Classes

This document discusses Java classes and objects. It provides examples of creating classes with fields like name and age, and creating objects of those classes. It also discusses static classes, getter and setter methods, and how to access private fields through getters and setters. Randomly generating numbers is demonstrated using the Random class. Built-in Java classes like LocalDate are shown for creating date objects.

Uploaded by

Bernal Familia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Java FD - Classes

This document discusses Java classes and objects. It provides examples of creating classes with fields like name and age, and creating objects of those classes. It also discusses static classes, getter and setter methods, and how to access private fields through getters and setters. Randomly generating numbers is demonstrated using the Random class. Built-in Java classes like LocalDate are shown for creating date objects.

Uploaded by

Bernal Familia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

agClasses LEa49LZB

classovete se pishat s glavna bukva kato Client, Name


static class Client {
String name;
int age;
int cents;
int numberOfDrinks;
}
primeren class v main methoda v main proekta
ako ne im zadadem stoinost shte izleze 0 pri default stoinostite

Client clientA = new Client();


Client clientB = new Client();

Kolkoto puti imame new v koda tolkova obekta imame ako imame
samo edin obekt

Client clientA = new Client();

To kakvito I zamestiteli da pravim na clientA I clientC v sluchaq

Shte sa edni I sushti zashtoto se zapazvat pod edin obekt v na edno I


sushto mqsto v pameta

Client clientC = clientA;


clientC.age++;
clientC.name = "Stamat";

Clasovete se pishat/inicializirat s glavna bukva

Obekta/object durji dadeni stoinosti, Ima obekt za rojden den

LocalDate birthday = LocalDate.of(2018, 5, 5); (year, month, day)


System.out.println(birthday);

birthday – object name

year/month/day – obejct fields

suzdavane na obekt ot veche definiran class se naricha instanciq

LocalDate date1 = LocalDate.of(2018, 5, 5);

LocalDate date2 = LocalDate.of(2016, 3, 5);

LocalDate date3 = LocalDate.of(2013, 3, 2);

Vsichki instancii imat edno I sushto izpulnenie/durjanie

Build-UP – API CLASSES


Random class
String[] words = scanner.nextLine().split(" ");

Random random = new Random();

for (int i = 0; i < words.length; i++) {


int first = random.nextInt(words.length);
int second = random.nextInt(words.length);
}

Random classa dava psevdo-proizvolno chislo

Koeto se izchislqva po nqkakvi formuli I ti dava chisloto tui kato pcto nemoje da
misli I izpulnqva comandi…

STATIC API CLASSES


LocalDateTime today = LocalDateTime.now();

double cosine = Math.cos(Math.PI);

java ni predostavq ready-to-use classes kato


java.util.Scanner, java.utils.List, etc..

Java ima I statichni classove kato


LocalDateTime today = LocalDateTime.now();

double cosine = Math.cos(Math.PI);

Math e class koito vika method koito vika class… etc etc..

GETTER& & SETTER&

Hubavo e kogato suzdavame nov class da e v razlichen


proekt/class/TAB zashtoto taka ako dannite sa private shte mojem da
slojim getteri I setteri I da gi dostupim ako classa go pravim v main
methoda to trqbva da e STATIC

No classovete v rabotata vsichki shte sa na otdelni tabove I shte


trqbva da im pravim getteri I setteri

Getterite ili vrushtat stoinosti return; ili izpulnqvat usloviq

private String name; // private dannite koito trqbva da


private int age; dostupim no sa private

public Person (String name, int age) { // pravim si class Person


this.name = name; sus zadadeni danni koito
this.age = age; shte budat dostupvani
}

public int getAge() {


return this.age;
} // I vrushtame stoinostite
za da moje da gi dostupim
public String getName() { v main methoda 
return this.name;
}
Nov class vuv otdelen tab!!! I sled tova zipvash za predavane v judge

Vinagi trqbva da ima Main(file) I classa za da moje da judge da gi


razlichi

Setterite promenqt stoinost

You might also like