-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethod_overinding.java
More file actions
43 lines (35 loc) · 1.15 KB
/
method_overinding.java
File metadata and controls
43 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//method overriding me same method 2 class me hti hain
//methd overloading me same methdd same class me hoti hai arguments unke alag alag hoti hai
/// IF CHILD CLASS IMPLIMENT THE SAME METHOD PRESENT IN THE PARENTS CLASS THEN IT IS METHOD OVERRINDING
//static method , final method kom override mahi kar sakte ]
class a
{
public int meth1()
{
return 4;
}
public void meth2()
{
System.out.println(" i am a meth 2 of class a");
}
}
class b extends a{
@Override //override ho rahi hai isiliye @override likh sakte hai ,, nahi likhenge tab bbhi chalega
public void meth2() //same method hai but 2 class me
{
System.out.println(" i am a meth 2 of class b");
}
public void meth3()
{
System.out.println(" i am a meth 3 of class b");
}
}
public class method_overinding {
public static void main(String[] args) {
a a1 = new a();
a1.meth2();
b b1 = new b(); // meth 2 ko b se bhi call karte hai;;;
// b1.meth2();
b1.meth2();
}
}