Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20250520
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
20250520
Commits
2d582b40
Commit
2d582b40
authored
May 21, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Klasa Osoba - konstruktory i metody
parent
ac7f09a4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletions
+60
-1
Osoba.java
src/p10_klasy_podstawy/Osoba.java
+28
-1
Program.java
src/p10_klasy_podstawy/Program.java
+32
-0
No files found.
src/p10_klasy_podstawy/Osoba.java
View file @
2d582b40
package
p10_klasy_podstawy
;
public
class
Osoba
{
final
static
int
WIEK_PELNOLETNIOSCI
=
18
;
String
imie
,
nazwisko
;
int
wiek
;
}
public
Osoba
()
{
}
public
Osoba
(
String
imie
,
String
nazwisko
,
int
wiek
)
{
this
.
imie
=
imie
;
this
.
nazwisko
=
nazwisko
;
this
.
wiek
=
wiek
;
}
public
void
przedstawSie
()
{
System
.
out
.
println
(
"Nazywam się "
+
imie
+
" "
+
nazwisko
+
" i mam "
+
wiek
+
" lat."
);
}
public
boolean
pelnoletnia
()
{
return
wiek
>=
WIEK_PELNOLETNIOSCI
;
}
public
String
toString
()
{
return
imie
+
" "
+
nazwisko
+
" ("
+
wiek
+
" lat)"
;
}
}
\ No newline at end of file
src/p10_klasy_podstawy/Program.java
View file @
2d582b40
...
...
@@ -7,5 +7,37 @@ public class Program {
System
.
out
.
println
(
a
.
toString
());
System
.
out
.
println
(
a
.
getClass
());
System
.
out
.
println
(
a
.
hashCode
());
System
.
out
.
println
();
System
.
out
.
println
(
"Początkowe wartości pól: "
+
a
.
imie
+
" "
+
a
.
nazwisko
+
" "
+
a
.
wiek
);
a
.
imie
=
"Ala"
;
a
.
nazwisko
=
"Kowalska"
;
a
.
wiek
=
30
;
System
.
out
.
println
(
"Wartości pól a: "
+
a
.
imie
+
" "
+
a
.
nazwisko
+
" "
+
a
.
wiek
);
// można tworzyć wiele obiektów tej samej klasy
Osoba
b
=
new
Osoba
();
b
.
imie
=
"Bartek"
;
b
.
nazwisko
=
"Malinowski"
;
b
.
wiek
=
30
;
System
.
out
.
println
(
"Wartości pól b: "
+
b
.
imie
+
" "
+
b
.
nazwisko
+
" "
+
b
.
wiek
);
System
.
out
.
println
();
a
.
przedstawSie
();
b
.
przedstawSie
();
System
.
out
.
println
();
System
.
out
.
println
(
a
);
System
.
out
.
println
(
b
);
String
napis1
=
a
.
toString
();
// ale to działa tylko dla istniejących obiektów
System
.
out
.
println
(
napis1
);
String
napis2
=
String
.
valueOf
(
b
);
// to działa dla dowolnych wartości: obiekty, typy proste, wartość null
System
.
out
.
println
(
napis2
);
System
.
out
.
println
();
Osoba
c
=
new
Osoba
(
"Celina"
,
"Nowakowska"
,
40
);
System
.
out
.
println
(
c
);
c
.
przedstawSie
();
// obiektów się nie usuwa
}
}
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