Skip to content

Commit 84b68c9

Browse files
authored
Update Exam_Notes.md
1 parent 35aec66 commit 84b68c9

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

Exam_Notes.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,63 @@ public class test {
7676
}
7777
}
7878
```
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+
79121

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+
```
80136
# Unit 4
81137
# Generic Method non return type
82138
``` java:

0 commit comments

Comments
 (0)