FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Projects/java-oops-concepts/src/Introduction/Main.java at main · shitu13/Java-Projects · GitHub
shitu13
/
Java-Projects
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Projects
/
java-oops-concepts
/
src
/
Introduction
/
Main.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (38 loc) · 1.16 KB
Breadcrumbs
Java-Projects
/
java-oops-concepts
/
src
/
Introduction
/
Main.java
Copy path
File metadata and controls
46 lines (38 loc) · 1.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
40
41
42
43
44
45
46
package
Introduction
;
/*
* Classes and Objects in Java.
*/
public
class
Main
{
public
static
void
main
(
String
[]
args
) {
// Creating objects from the Car class
Car
car1
=
new
Car
(
"Red"
,
"Toyota"
,
2020
);
Car
car2
=
new
Car
(
"Blue"
,
"Honda"
,
2019
);
// Accessing fields and methods
car1
.
displayInfo
();
// Output: Car model: Toyota, Color: Red, Year: 2020
car1
.
startEngine
();
// Output: Engine started.
car2
.
displayInfo
();
// Output: Car model: Honda, Color: Blue, Year: 2019
car2
.
stopEngine
();
// Output: Engine stopped.
}
}
class
Car
{
// Fields (or instance variables)
String
color
;
String
model
;
int
year
;
// Constructor
public
Car
(
String
color
,
String
model
,
int
year
) {
this
.
color
=
color
;
this
.
model
=
model
;
this
.
year
=
year
;
}
// Methods
public
void
displayInfo
() {
System
.
out
.
println
(
"Car model: "
+
model
+
", Color: "
+
color
+
", Year: "
+
year
);
}
public
void
startEngine
() {
System
.
out
.
println
(
"Engine started."
);
}
public
void
stopEngine
() {
System
.
out
.
println
(
"Engine stopped."
);
}
}
Back
|
FazBrowse Home
|
New Git URL