Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jvstd1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
jvstd1
Commits
3fcfc39f
Commit
3fcfc39f
authored
Sep 11, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pola
parent
537d65bd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
Osoba.java
src/main/java/p05_klasy_wstep/Osoba.java
+13
-0
Program1.java
src/main/java/p05_klasy_wstep/Program1.java
+28
-0
No files found.
src/main/java/p05_klasy_wstep/Osoba.java
View file @
3fcfc39f
package
p05_klasy_wstep
;
package
p05_klasy_wstep
;
public
class
Osoba
{
public
class
Osoba
{
/* W klasach można umieszczać:
- zmienne - statyczne lub "instancyjne"; na zmienne w klasach mówi się też "pola" lub "atrybuty"
- metody - statycznych lub instancyjnych
- konstruktory
- bloki inicjalizacyjne - statyczne lub instancyjne
- klasy zagnieżdżone - statyczne lub instancyjne
- szczególnym przypadkiem mogą być zagieżdżone interfejsy, enumy, rekordy - niektóre z nich są tylko statyczne
*/
// zmienne (pola) deklarowane bez słowa static należą do obiektów danej klasy (każdy obiekt ma swoje pola)
String
imie
,
nazwisko
;
int
wiek
;
}
}
src/main/java/p05_klasy_wstep/Program1.java
0 → 100644
View file @
3fcfc39f
package
p05_klasy_wstep
;
public
class
Program1
{
public
static
void
main
(
String
[]
args
)
{
Osoba
a
=
new
Osoba
();
Osoba
b
=
new
Osoba
();
// Pola w obiektach są automatycznie inicjalizowane na wartości
// null - dla pól typu obiektowego
// 0 - dla typów prostych liczbowych
// false - dla typu boolean
System
.
out
.
println
(
"Początkowe wartości pól: "
+
a
.
imie
+
" "
+
a
.
nazwisko
+
" "
+
a
.
wiek
);
// bezpośrednie używanie pól obiektu jest możliwe, o ile te pola nie są prywatne
a
.
imie
=
"Ala"
;
a
.
nazwisko
=
"Kowalska"
;
a
.
wiek
=
16
;
b
.
imie
=
"Ola"
;
b
.
nazwisko
=
"Malinowska"
;
b
.
wiek
=
26
;
b
.
wiek
++;
System
.
out
.
println
(
"pola a: "
+
a
.
imie
+
" "
+
a
.
nazwisko
+
" "
+
a
.
wiek
);
System
.
out
.
println
(
"pola b: "
+
b
.
imie
+
" "
+
b
.
nazwisko
+
" "
+
b
.
wiek
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment