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
537d65bd
Commit
537d65bd
authored
Sep 11, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Początek tematu klas
parent
ecc3e7d9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
0 deletions
+62
-0
vcs.xml
.idea/vcs.xml
+7
-0
SwitchNaObiektach.java
src/main/java/p04_switch/SwitchNaObiektach.java
+7
-0
Osoba.java
src/main/java/p05_klasy_wstep/Osoba.java
+4
-0
Program0.java
src/main/java/p05_klasy_wstep/Program0.java
+44
-0
No files found.
.idea/vcs.xml
0 → 100644
View file @
537d65bd
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"$PROJECT_DIR$"
vcs=
"Git"
/>
</component>
</project>
\ No newline at end of file
src/main/java/p04_switch/SwitchNaObiektach.java
View file @
537d65bd
...
@@ -30,6 +30,13 @@ public class SwitchNaObiektach {
...
@@ -30,6 +30,13 @@ public class SwitchNaObiektach {
case
null
->
System
.
out
.
println
(
"Nie ma nic"
);
case
null
->
System
.
out
.
println
(
"Nie ma nic"
);
default
->
System
.
out
.
println
(
"Nie wiem co to jest. Ale klasą jest "
+
jakisObiekt
.
getClass
());
default
->
System
.
out
.
println
(
"Nie wiem co to jest. Ale klasą jest "
+
jakisObiekt
.
getClass
());
}
}
// w starym stylu byłoby tak:
if
(
jakisObiekt
instanceof
String
)
{
String
s
=
(
String
)
jakisObiekt
;
if
(
s
.
startsWith
(
"o"
))
System
.
out
.
println
(
"To jest napis na o:"
+
s
);
// ...
}
}
}
}
}
...
...
src/main/java/p05_klasy_wstep/Osoba.java
0 → 100644
View file @
537d65bd
package
p05_klasy_wstep
;
public
class
Osoba
{
}
src/main/java/p05_klasy_wstep/Program0.java
0 → 100644
View file @
537d65bd
package
p05_klasy_wstep
;
public
class
Program0
{
public
static
void
main
(
String
[]
args
)
{
// sama deklaracja zmiennej nie tworzy jeszcze obiektu - to jest "niezainicjowana zmienna"
Osoba
a
;
// System.out.println(a);
// obiekt tworzy się za pomocą operatora new
a
=
new
Osoba
();
System
.
out
.
println
(
a
);
// zazwyczaj deklarując zmienną od razu wpisuje się tam obiekt:
Osoba
b
=
new
Osoba
();
System
.
out
.
println
(
b
);
// do zmiennych typu obiektowego można też wpisać wartość null, co znaczy "tu nie ma żadnego obiektu"
Osoba
nikt
=
null
;
System
.
out
.
println
(
nikt
);
System
.
out
.
println
();
// każdy obiekt w Javie, nawet jeśli definicja klasy jest zupełnie pusta,
// posiada takie metody:
// info jakiej klasy jest obiekt
System
.
out
.
println
(
a
.
getClass
());
// zamiana na postać tekstową
System
.
out
.
println
(
a
.
toString
());
// metody związane z porównywaniem
// equals - czy obiekt jest równy obiektowi
System
.
out
.
println
(
a
.
equals
(
a
));
System
.
out
.
println
(
a
.
equals
(
b
));
// hashCode - liczba traktowana jako "skrót" obiektu
// hc muszą być równe jeśli obiekty są równe; dobrze by było, aby hc były różne dla różnych obiektów - ale tego w pełni się nie gwarantuje
System
.
out
.
println
(
a
.
hashCode
());
System
.
out
.
println
(
b
.
hashCode
());
// metody toString, equals, hashCode może przedefiniować autor danej klasy (i b.często się tak robi)
// metody wait i notify (w kilku wariantach) są związane z wielowątkowością i synchronizacją - nie teraz...
}
}
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