-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethods.java
More file actions
27 lines (26 loc) · 870 Bytes
/
Methods.java
File metadata and controls
27 lines (26 loc) · 870 Bytes
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
// package Object_Oriented_Programming;
// car - we have modules engine,brake,accelator,wheels..etc
class Computer{
public void playMusic(){ // method
System.out.println("Music Played!");
}
public String getMeAPen(int cost){ /* provide money then i will give you a pen */
if (cost>=10){
return "Pen"; // returning a string
}
else{
return "Only Pens With Greater Than 10 Rupees Are Available, you get Nothing";
}
}
}
public class Methods {
public static void main(String args[]){
Computer obj = new Computer(); // created an object
obj.playMusic();
// obj.getClass(); // save in variable
String x = obj.getMeAPen(20);
System.out.println(x);
String y = obj.getMeAPen(5);
System.out.println(y);
}
}