-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_oop.java
31 lines (29 loc) · 921 Bytes
/
first_oop.java
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
// class Calculator{
// int a;
// public int add(){
// System.out.println("in add");
// return 0;
// }
// }
class Calculator {
public int add(int n1, int n2) {
// System.out.println("in add");
return n1 + n2;
}
}
public class first_oop {
public static void main(String args[]) {
int num1 = 4;
int num2 = 7;
int result = num1 + num2;
System.out.println(result);
// how to call the add function
// creating object of class
// Calculator calc; /// just created an refrence so it still does not work
// you have to give space to object.
Calculator calc = new Calculator(); // this is how we create objects
result = calc.add(num1, num2);
System.out.println(result);
}
}
// every object has properties-behaviour/action will be done using methods