Skip to content

Commit 0aba8d8

Browse files
Method Overriding in Java
1 parent 6a960cd commit 0aba8d8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class A {
2+
public int a;
3+
public int harry() {
4+
return 4;
5+
}
6+
public void meth2() {
7+
System.out.println("I am method 2 of class A");
8+
}
9+
}
10+
11+
class B extends A {
12+
@Override
13+
public void meth2() {
14+
System.out.println("I am method 2 of class B");
15+
}
16+
public void meth3() {
17+
System.out.println("I am method 3 of class B");
18+
}
19+
}
20+
21+
public class cwh_48_method_overriding {
22+
public static void main(String[] args) {
23+
A a = new A();
24+
a.meth2();
25+
26+
B b = new B();
27+
b.meth2();
28+
}
29+
}

0 commit comments

Comments
 (0)