-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOPS.java
More file actions
132 lines (104 loc) · 2.55 KB
/
Copy pathOOPS.java
File metadata and controls
132 lines (104 loc) · 2.55 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
public class OOPS {
public static void main(String[] args) {
// Student s1 = new Student("Karan");
// System.out.println(s1.name);
// Fish shark = new Fish();
// shark.eat();
// Dog Sheru = new Dog();
// Sheru.eat();
// Sheru.legs = 4;
// System.out.println(Sheru.legs);
// Calculator calc = new Calculator();
// System.out.println(calc.sum(5, 5));
// System.out.println(calc.sum(5, 3, 2));
// System.out.println(calc.sum((float)5.0, (float)5.0));
// Cow Nando = new Cow();
// Nando.eat();
}
}
// class Student{
// String name;
// int roll_no;
// Student(String name){
// this.name = name;
// }
// }
//This is example of Single level Inheritance
//Base Class
// class Animal{
// String color;
// void eat(){
// System.out.println("Eats");
// }
// void breathe(){
// System.out.println("Breathes");
// }
// }
// //Derived class
// class Fish extends Animal {
// int fins;
// void swim(){
// System.out.println("Swims");
// }
// }
//This is example of Multilevel Inheritance
// this is base class
// class Animal{
// String color;
// void eat(){
// System.out.println("Eats");
// }
// void breathe(){
// System.out.println("Breathes");
// }
// }
// this is derived class from animal
// class Mammal extends Animal{
// int legs;
// }
// this is derived class derived from a derived class
// class Dog extends Mammal{
// String breed;
// }
// This is example of Heirarchial Inheritance
// This is base class
// class Animal{
// String color;
// void eat(){
// System.out.println("Eats");
// }
// void breathe(){
// System.out.println("Breathes");
// }
// }
// this is derived class1 derived from animal
// class Mammal extends Animal{
// int legs;
// }
// // this is derived class2 derived from animal
// class Dog extends Animal{
// String breed;
// }
// this is example of method overloading(Polymorphism)
// class Calculator{
// int sum(int a,int b){
// return a+b;
// }
// int sum(int a,int b,int c){
// return a+b+c;
// }
// float sum(float a, float b){
// return a+b;
// }
// }
// This is example of method overriding(Polymorphism)
// class Animal{
// void eat(){
// System.out.println("Eats anything");
// }
// }
// class Cow extends Animal{
// void eat(){
// System.out.println("Eats only Grass");
// }
// }