From 68a61a0213e05ff3ca1fd3ff7e109c687ead7d80 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Sun, 19 Apr 2026 12:06:37 +0800 Subject: [PATCH 1/5] Committed on or around 2026/04/19 --- .../Intro_to_CS_No17_2026.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Miscellaneous/L4_Civil_Servant_Admission_Exam/Intro_to_CS_No17_2026.java diff --git a/Miscellaneous/L4_Civil_Servant_Admission_Exam/Intro_to_CS_No17_2026.java b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Intro_to_CS_No17_2026.java new file mode 100644 index 0000000..3ea27b6 --- /dev/null +++ b/Miscellaneous/L4_Civil_Servant_Admission_Exam/Intro_to_CS_No17_2026.java @@ -0,0 +1,29 @@ +package L4_Civil_Servant_Admission_Exam; + +public class Intro_to_CS_No17_2026 { + + public static void main(String[] args) { + + int month = 1; + + while(month <= 4) { + + switch(month) { + + case 1: + System.out.println("31"); + + case 2: + System.out.println("28"); + + case 4: + System.out.println("30"); + + } + + month++; + } + + } + +} From 9c635208ecb38e4eb9387a0cf75d2f70d068513f Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:22:07 +0800 Subject: [PATCH 2/5] Committed on 2025/06/11 --- Chapter7/SupSubRef2.java | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Chapter7/SupSubRef2.java diff --git a/Chapter7/SupSubRef2.java b/Chapter7/SupSubRef2.java new file mode 100644 index 0000000..2e19ecc --- /dev/null +++ b/Chapter7/SupSubRef2.java @@ -0,0 +1,41 @@ +// A superclass reference can refer to a subclass object. + +class X3 { + int a; + + public X3(int i) { + // TODO Auto-generated constructor stub + + a = i; + } +} + +class Y3 extends X3 { + int b; + + public Y3(int i, int j) { + // TODO Auto-generated constructor stub + super(j); + b = i; + } +} + +public class SupSubRef2 { + + public static void main(String[] args) { + + X3 x = new X3(10); + Y3 y = new Y3(5, 6); + + System.out.println("X.a: " + x.a); + + x = y; + System.out.println("X.a: " + x.a); + + // X references know only about X members + x.a = 19; // OK +// x2.b = 27; // Error, X does not have a b member. + + } + +} From 129bb515c3813c1afd514c616516ab2c543bafef Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:26:55 +0800 Subject: [PATCH 3/5] Committed on or around 2026/06/11 --- Chapter7/SupSubRef2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter7/SupSubRef2.java b/Chapter7/SupSubRef2.java index 2e19ecc..ce10dac 100644 --- a/Chapter7/SupSubRef2.java +++ b/Chapter7/SupSubRef2.java @@ -34,7 +34,7 @@ public static void main(String[] args) { // X references know only about X members x.a = 19; // OK -// x2.b = 27; // Error, X does not have a b member. +// x.b = 27; // Error, X does not have a b member. } From f0837941c52bd708db12fa700a2545b8078901c7 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:37:57 +0800 Subject: [PATCH 4/5] Committed on 2026/06/11 --- Chapter7/Dynamic_Disptach_Demo_2.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Chapter7/Dynamic_Disptach_Demo_2.java diff --git a/Chapter7/Dynamic_Disptach_Demo_2.java b/Chapter7/Dynamic_Disptach_Demo_2.java new file mode 100644 index 0000000..318154e --- /dev/null +++ b/Chapter7/Dynamic_Disptach_Demo_2.java @@ -0,0 +1,24 @@ + +public class Dynamic_Disptach_Demo_2 { + + public static void main(String[] args) { + + Sup superOb = new Sup(); + Sub1 subOb1 = new Sub1(); + Sub2 subOb2 = new Sub2(); + + Sup supRef; // Declaring a variable called supRef of the class type Sup. This variable does not define an object. Instead, it is simply a variable that can refer to an object. + + supRef = superOb; + supRef.who(); // In each case, the version of who() to call is determined at run time by ... + + supRef = subOb1; + supRef.who(); // ... the type of object being referred to. + + supRef = subOb2; + supRef.who(); + + + } + +} From 98bd68093662581b3e24552686a1ab0b046dec80 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 11 Jun 2026 16:52:58 +0800 Subject: [PATCH 5/5] Committed on or around 2026/06/11 --- Chapter7/Dynamic_Disptach_Demo_2.java | 15 +++++---------- Chapter7/SupSubRef2.java | 14 +++++++------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Chapter7/Dynamic_Disptach_Demo_2.java b/Chapter7/Dynamic_Disptach_Demo_2.java index 318154e..9babea9 100644 --- a/Chapter7/Dynamic_Disptach_Demo_2.java +++ b/Chapter7/Dynamic_Disptach_Demo_2.java @@ -4,19 +4,14 @@ public class Dynamic_Disptach_Demo_2 { public static void main(String[] args) { Sup superOb = new Sup(); - Sub1 subOb1 = new Sub1(); - Sub2 subOb2 = new Sub2(); - Sup supRef; // Declaring a variable called supRef of the class type Sup. This variable does not define an object. Instead, it is simply a variable that can refer to an object. + superOb.who(); // In each case, the version of who() to call is determined at run time by ... - supRef = superOb; - supRef.who(); // In each case, the version of who() to call is determined at run time by ... + superOb = new Sub1(); + superOb.who(); // ... the type of object being referred to. - supRef = subOb1; - supRef.who(); // ... the type of object being referred to. - - supRef = subOb2; - supRef.who(); + superOb = new Sub2(); + superOb.who(); } diff --git a/Chapter7/SupSubRef2.java b/Chapter7/SupSubRef2.java index ce10dac..3a9a0a3 100644 --- a/Chapter7/SupSubRef2.java +++ b/Chapter7/SupSubRef2.java @@ -24,17 +24,17 @@ public class SupSubRef2 { public static void main(String[] args) { - X3 x = new X3(10); - Y3 y = new Y3(5, 6); + X3 x3 = new X3(10); + Y3 y3 = new Y3(5, 6); - System.out.println("X.a: " + x.a); + System.out.println("X.a: " + x3.a); - x = y; - System.out.println("X.a: " + x.a); + x3 = y3; + System.out.println("X.a: " + x3.a); // X references know only about X members - x.a = 19; // OK -// x.b = 27; // Error, X does not have a b member. + x3.a = 19; // OK +// x3.b = 27; // Error, X does not have a b member. }