Tutorial 5
This commit is contained in:
parent
1435fb21b9
commit
53e70432fe
|
@ -3,6 +3,7 @@
|
|||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="22" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -5,7 +5,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -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>
|
|
@ -0,0 +1,11 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
ClassF z = new ClassF();
|
||||
|
||||
z.print(9);
|
||||
z.print(2, "Cx2002");
|
||||
z.print("Object");
|
||||
z.print("OODP", "Java");
|
||||
// z.print("OODP", 2002); // Compilation error
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassA {
|
||||
public void print(int x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassB extends ClassA {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
public abstract class ClassC extends ClassA {
|
||||
public abstract void print(String x, String y);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassD extends ClassC {
|
||||
public void print(String a, String b) {
|
||||
System.out.println(a + " " + b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
public class ClassE extends ClassC {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
public void print(String x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassF extends ClassE {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassG extends ClassF {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
ClassF z = new ClassF();
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassA {
|
||||
public void print(int x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassB extends ClassA {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
public abstract class ClassC extends ClassA {
|
||||
public abstract void print(String x, String y);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassD extends ClassC {
|
||||
public void print(String a, String b) {
|
||||
System.out.println(a + " " + b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
public abstract class ClassE extends ClassC {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
public abstract void print(String x, String y);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
public class ClassF extends ClassE {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
public void print(String x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
public class ClassG extends ClassF {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
public void print(String x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassA {
|
||||
public void print(int x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassB extends ClassA {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
public abstract class ClassC extends ClassA {
|
||||
public abstract void print(String x, String y);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassD extends ClassC {
|
||||
public void print(String a, String b) {
|
||||
System.out.println(a + " " + b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassE extends ClassC {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassF extends ClassE {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassG extends ClassF {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
ClassF z = new ClassF();
|
||||
}
|
||||
}
|
|
@ -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="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassA {
|
||||
public void print(int x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassB extends ClassA {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
public abstract class ClassC extends ClassA {
|
||||
public abstract void print(String x, String y);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassD extends ClassC {
|
||||
public void print(String a, String b) {
|
||||
System.out.println(a + " " + b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
public class ClassE extends ClassC {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
public void print(String x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassF extends ClassE {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassG extends ClassF {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// I - Works
|
||||
// ClassC c = new ClassD();
|
||||
// c.print("hello", "there");
|
||||
|
||||
// II - Does not compile because class C is abstract
|
||||
// ClassA a = new ClassC();
|
||||
// a.print(1, "there");
|
||||
|
||||
// III - Doesn't work - Class A does not have print(string, string) method
|
||||
// ClassA a = new ClassF();
|
||||
// a.print("hello", "there");
|
||||
}
|
||||
}
|
|
@ -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="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassA {
|
||||
public void print(int x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassB extends ClassA {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
public abstract class ClassC extends ClassA {
|
||||
public abstract void print(String x, String y);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassD extends ClassC {
|
||||
public void print(String a, String b) {
|
||||
System.out.println(a + " " + b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
public abstract class ClassE extends ClassC {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
public abstract void print(String x, String y);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
public class ClassF extends ClassE {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
public void print(String x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
public class ClassG extends ClassF {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
public void print(String x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// I - Works
|
||||
ClassC c = new ClassD();
|
||||
c.print("hello", "there");
|
||||
|
||||
// II - Does not compile because class C is abstract
|
||||
// ClassA a = new ClassC();
|
||||
// a.print(1, "there")
|
||||
|
||||
// III - Works
|
||||
ClassF a = new ClassF();
|
||||
a.print("hello", "there");
|
||||
}
|
||||
}
|
|
@ -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="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassA {
|
||||
public void print(int x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassB extends ClassA {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassC extends ClassA {
|
||||
public void print(String x, String y) {
|
||||
System.out.println(x + " " + y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassD extends ClassC {
|
||||
public void print(String a, String b) {
|
||||
System.out.println(a + " " + b);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassE extends ClassC {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassF extends ClassE {
|
||||
public void print(int x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
public class ClassG extends ClassF {
|
||||
public void print(String x) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// I - Doesn't work because downcast needs to be explicitly declared
|
||||
// ClassC c = new ClassD();
|
||||
// ClassE e = c;
|
||||
// ClassE e = (ClassE) c;
|
||||
|
||||
// II - Can´t upcast because they are from different family branches
|
||||
// ClassB b = new ClassE();
|
||||
// b.print("hello");
|
||||
|
||||
// III
|
||||
// ClassA a = new ClassF(); // Ok
|
||||
// a.print(12, "there"); // Ok
|
||||
// a.print(88); // Compilation error
|
||||
|
||||
// IV
|
||||
// ClassA a = new ClassC(); // Ok
|
||||
// ClassG g = new (ClassG)a; // Syntax error
|
||||
// g.print("hello"); // RunTime error: trick
|
||||
|
||||
// V
|
||||
// ClassA a = new ClassC(); // ok
|
||||
// ClassG g = (ClassG)a; // ok
|
||||
// g.print("hello", "there"); // Runtime error: trick
|
||||
|
||||
// VI
|
||||
// ClassA a = new ClassF(); // OK
|
||||
// ClassC f = (ClassC)a; // Ok
|
||||
// f.print(88, "there"); // Ok
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -29,16 +29,6 @@ public class TestPolygon {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue