-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathClassDemo.java
More file actions
39 lines (31 loc) · 793 Bytes
/
ClassDemo.java
File metadata and controls
39 lines (31 loc) · 793 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
28
29
30
31
32
33
34
35
36
37
38
39
/**
* The ClassDemo program implements an application that
* simply demonstrates class and object creation in Java
*
* @author Sarju S
* @version 1.0
* @since 2020-09-28
*/
package com.sjcet.oopdemo;
class Lamp {
boolean isOn;
void turnOn() {
// initialize variable with value true
isOn = true;
System.out.println("Light on? " + isOn);
}
void turnOff() {
// initialize variable with value false
isOn = false;
System.out.println("Light on? " + isOn);
}
}
public class ClassDemo {
public static void main(String[] args) {
//Create Object Reference and Object to it
Lamp lamp = new Lamp();
// call methods turnOn() and turnOff()
lamp.turnOn();
lamp.turnOff();
}
}