File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,63 @@ public class test {
76
76
}
77
77
}
78
78
```
79
+ # Overloading
80
+ ``` java:
81
+ class Example {
82
+ public void print(int x) {
83
+ System.out.println("Printing integer: " + x);
84
+ }
85
+
86
+ public void print(double x) {
87
+ System.out.println("Printing double: " + x);
88
+ }
89
+
90
+ public void print(String x) {
91
+ System.out.println("Printing string: " + x);
92
+ }
93
+ }
94
+ public class test {
95
+ public static void main(String[] args)
96
+ {
97
+ Example example = new Example();
98
+ example.print(5); // Prints "Printing integer: 5"
99
+ example.print(3.14); // Prints "Printing double: 3.14"
100
+ example.print("Hello"); // Prints "Printing string: Hello"
101
+
102
+ }
103
+ }
104
+ ```
105
+
106
+ # Overriding
107
+ ``` java
108
+ class Animal {
109
+ public void makeSound () {
110
+ System . out. println(" The animal makes a sound" );
111
+ }
112
+ }
113
+
114
+ class Dog extends Animal {
115
+ @Override
116
+ public void makeSound () {
117
+ System . out. println(" The dog barks" );
118
+ }
119
+ }
120
+
79
121
122
+ public class test {
123
+ public static void main (String [] args )
124
+ {
125
+ Animal animal = new Animal ();
126
+ animal. makeSound(); // Prints "The animal makes a sound"
127
+
128
+ Dog dog = new Dog ();
129
+ dog. makeSound(); // Prints "The dog barks"
130
+
131
+
132
+
133
+ }
134
+ }
135
+ ```
80
136
# Unit 4
81
137
# Generic Method non return type
82
138
``` java:
You can’t perform that action at this time.
0 commit comments