Created
February 23, 2018 22:30
-
-
Save viveknarang/1efd6ec44ec9030df4d4e97c4c3fa0c1 to your computer and use it in GitHub Desktop.
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
public class OOPExample { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Numbers num = new Numbers(1, 2); | |
System.out.println(num.sum()); | |
Numbers num2 = new Numbers(); | |
num2.x = 5; | |
num2.y = 15; | |
System.out.println(num2.diff()); | |
} | |
} | |
----- | |
public class Numbers { | |
double x; | |
double y; | |
public Numbers(double x, double y) { | |
this.x = x; | |
this.y = y; | |
} | |
public Numbers() { | |
super(); | |
} | |
public double sum() { | |
double c = x + y; | |
return c; | |
} | |
public double multiply() { | |
double c = x * y; | |
return c; | |
} | |
public double diff() { | |
double c = x - y; | |
return c; | |
} | |
public double div() { | |
double c = x / y; | |
return c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment