fix: Interfaces and Abstract classes
This commit is contained in:
parent
6b7d95a461
commit
8292e4e272
29
Interfaces/.gitignore
vendored
Normal file
29
Interfaces/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
3
Interfaces/.idea/.gitignore
vendored
Normal file
3
Interfaces/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
7
Interfaces/.idea/codeStyles/Project.xml
Normal file
7
Interfaces/.idea/codeStyles/Project.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<ScalaCodeStyleSettings>
|
||||
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
|
||||
</ScalaCodeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
5
Interfaces/.idea/codeStyles/codeStyleConfig.xml
Normal file
5
Interfaces/.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
6
Interfaces/.idea/git_toolbox_blame.xml
Normal file
6
Interfaces/.idea/git_toolbox_blame.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GitToolBoxBlameSettings">
|
||||
<option name="version" value="2" />
|
||||
</component>
|
||||
</project>
|
||||
6
Interfaces/.idea/misc.xml
Normal file
6
Interfaces/.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
Interfaces/.idea/modules.xml
Normal file
8
Interfaces/.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Interfaces.iml" filepath="$PROJECT_DIR$/Interfaces.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
Interfaces/.idea/vcs.xml
Normal file
6
Interfaces/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
11
Interfaces/Interfaces.iml
Normal file
11
Interfaces/Interfaces.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
14
Interfaces/src/CountingSender.java
Normal file
14
Interfaces/src/CountingSender.java
Normal file
@ -0,0 +1,14 @@
|
||||
public abstract class CountingSender {
|
||||
private String prefix;
|
||||
private int counter;
|
||||
|
||||
public CountingSender(String prefix){
|
||||
this.prefix = prefix;
|
||||
}
|
||||
public void Greet(String message){
|
||||
this.counter ++;
|
||||
this.write("%d: %s,%s".formatted(this.counter, this.prefix, message));
|
||||
}
|
||||
|
||||
abstract void write(String message);
|
||||
}
|
||||
11
Interfaces/src/MessageSender.java
Normal file
11
Interfaces/src/MessageSender.java
Normal file
@ -0,0 +1,11 @@
|
||||
public class MessageSender extends CountingSender {
|
||||
|
||||
public MessageSender(String prefix) {
|
||||
super(prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
void write(String message) {
|
||||
System.out.println("- " + message);
|
||||
}
|
||||
}
|
||||
6
Interfaces/src/Sender.java
Normal file
6
Interfaces/src/Sender.java
Normal file
@ -0,0 +1,6 @@
|
||||
public interface Sender {
|
||||
void send(String message);
|
||||
default void Greet(String prefix, String message){
|
||||
send(prefix + " ---- " + message);
|
||||
}
|
||||
}
|
||||
16
Interfaces/src/TextSender.java
Normal file
16
Interfaces/src/TextSender.java
Normal file
@ -0,0 +1,16 @@
|
||||
public class TextSender implements Sender{
|
||||
@Override
|
||||
public void send(String message) {
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
var txtSender = new TextSender();
|
||||
txtSender.Greet("Hello", "Naruto");
|
||||
System.out.println("---");
|
||||
var msgSender = new MessageSender("Hello");
|
||||
msgSender.Greet(" Sasuke");
|
||||
msgSender.Greet(" Ichigo");
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user