FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
programming/objects/java/Student.java at master · Mrigank11/programming · GitHub
Mrigank11
/
programming
Public
forked from
hacktoberfest17/programming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
programming
/
objects
/
java
/
Student.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (37 loc) · 1.15 KB
Breadcrumbs
programming
/
objects
/
java
/
Student.java
Copy path
File metadata and controls
37 lines (37 loc) · 1.15 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
//object is an instance of a class
//lets write a class called student
public
class
Student
{
int
rollno
;
String
name
;
char
gender
;
double
gpa
;
//lets write a constructor
public
Student
(
int
rollno
,
String
name
,
char
gender
,
double
gpa
){
this
.
rollno
=
rollno
;
this
.
name
=
name
;
this
.
gender
=
gender
;
this
.
gpa
=
gpa
;
}
public
void
setId
(
int
id
){
this
.
rollno
=
id
;
}
public
void
setName
(
String
name
){
this
.
name
=
name
;
}
public
double
getGPA
(){
return
gpa
;
}
public
char
getGender
(){
return
gender
;
}
public
static
void
main
(
String
[]
args
) {
Student
s1
=
new
Student
(
19
,
"ram"
,
'M'
,
9.5
);
//creating a student object
Student
s2
=
new
Student
(
21
,
"Sarvani"
,
'F'
,
9.62
);
//creating a student object using constructor
//now we can add and access student details using student object
s1
.
setId
(
20
);
s1
.
setName
(
"John"
);
System
.
out
.
println
(
"Id: "
+
s1
.
rollno
+
" Name: "
+
s1
.
name
+
" gender: "
+
s1
.
gender
+
" gpa: "
+
s1
.
gpa
);
System
.
out
.
println
(
"Id: "
+
s2
.
rollno
+
" Name: "
+
s2
.
name
+
" gender: "
+
s2
.
gender
+
" gpa: "
+
s2
.
gpa
);
System
.
out
.
println
(
s1
instanceof
Student
);
// displays true or false
}
}
Back
|
FazBrowse Home
|
New Git URL