-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add java object oriented proble solution
- Loading branch information
1 parent
17ccf58
commit db17481
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
java/object-oriented-programming/java-inheritance-i/java-inheritance-i.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
class Animal{ | ||
void walk() | ||
{ | ||
System.out.println("I am walking"); | ||
} | ||
} | ||
class Bird extends Animal | ||
{ | ||
void fly() | ||
{ | ||
System.out.println("I am flying"); | ||
} | ||
|
||
void sing() | ||
{ | ||
System.out.println("I am singing"); | ||
} | ||
} | ||
|
||
public class Solution{ | ||
|
||
public static void main(String args[]){ | ||
|
||
Bird bird = new Bird(); | ||
bird.walk(); | ||
bird.fly(); | ||
bird.sing(); | ||
|
||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
java/object-oriented-programming/java-inheritance-ii/java-inheritance-ii.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
//Write your code here | ||
class Arithmetic { | ||
public int add(int num1, int num2) { | ||
return num1 + num2; | ||
} | ||
} | ||
|
||
class Adder extends Arithmetic { | ||
|
||
} | ||
|
||
public class Solution{ | ||
public static void main(String []args){ | ||
// Create a new Adder object | ||
Adder a = new Adder(); | ||
|
||
// Print the name of the superclass on a new line | ||
System.out.println("My superclass is: " + a.getClass().getSuperclass().getName()); | ||
|
||
// Print the result of 3 calls to Adder's `add(int,int)` method as 3 space-separated integers: | ||
System.out.print(a.add(10,32) + " " + a.add(10,3) + " " + a.add(10,10) + "\n"); | ||
} | ||
} |
Empty file.