Skip to content

Commit 87c312a

Browse files
Naveen KhuntetaNaveen Khunteta
authored andcommitted
added code for inheritance
1 parent 5cd9640 commit 87c312a

8 files changed

Lines changed: 78 additions & 2 deletions

File tree

42 Bytes
Binary file not shown.

bin/OOPConcept/BMW.class

584 Bytes
Binary file not shown.

bin/OOPConcept/Car.class

666 Bytes
Binary file not shown.

bin/OOPConcept/TestCar.class

925 Bytes
Binary file not shown.

src/JavaSessions/StringManipulation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class StringManipulation {
44

55
public static void main(String[] args) {
66

7-
String s = "The rains have started here";
7+
String s = "The rains have started here selenium";
88

99
System.out.println(s.length());
1010

@@ -55,7 +55,6 @@ public static void main(String[] args) {
5555
String firstName1[] = firstName.split(";");
5656
for(int i=0; i<firstName1.length; i++){
5757
System.out.println(firstName1[i]);
58-
5958
}
6059

6160

src/OOPConcept/BMW.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package OOPConcept;
2+
3+
public class BMW extends Car{
4+
5+
//Method Overriding:
6+
//when the method name is same with the same number of arguments
7+
//in parent class as well as in child class
8+
public void start(){
9+
System.out.println("BMW--start");
10+
}
11+
12+
13+
public void theftSafety(){
14+
System.out.println("BMW--thefetSafety");
15+
}
16+
17+
18+
19+
20+
21+
22+
}

src/OOPConcept/Car.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package OOPConcept;
2+
3+
public class Car {
4+
5+
public void start(){
6+
System.out.println("Car--start");
7+
}
8+
9+
public void stop(){
10+
System.out.println("Car--stop");
11+
}
12+
13+
public void refuel(){
14+
System.out.println("Car--refuel");
15+
}
16+
17+
18+
19+
20+
21+
}

src/OOPConcept/TestCar.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package OOPConcept;
2+
3+
public class TestCar {
4+
5+
public static void main(String[] args) {
6+
7+
BMW b = new BMW();
8+
b.start(); //compile time polymorphism
9+
b.stop();
10+
b.refuel();
11+
b.theftSafety();
12+
13+
System.out.println("*******");
14+
15+
Car c = new Car();
16+
c.start();
17+
c.stop();
18+
c.refuel();
19+
20+
System.out.println("*******");
21+
22+
Car c1 = new BMW();//child class object can be referred by parent class reference variable
23+
//dynamic/Run Time polymorphism
24+
//Top casting
25+
c1.start();
26+
c1.stop();
27+
c1.refuel();
28+
29+
BMW b1 = (BMW) new Car(); //down casting: ClassCastException
30+
31+
32+
}
33+
34+
}

0 commit comments

Comments
 (0)