1. 예제
-> 학생관련 클래스를 선언한다.
-> 수학,영어,국어,자바,평균,등급,총합 변수를 선언한다.
2. 코드
package java_learn;
class Student {
int math;
int kor;
int eng;
int java;
double avg;
String grade;
int getTotal() {
return math + kor + eng + java;
}
}
public class java1 {
public static void main(String[] args) {
Student st1 = new Student();
Student st2 = new Student();
Student st3 = new Student();
st1.math = 20;
st2.math = 30;
st3.math = 40;
System.out.println(st1.math);
System.out.println(st2.math);
System.out.println(st3.math);
System.out.println(st1);
System.out.println(st2);
System.out.println(st3);
}
}
'IT > JAVA' 카테고리의 다른 글
JAVA - 예제 - 생성자 (0) | 2023.06.12 |
---|---|
JAVA - 예제 - this (0) | 2023.06.12 |
JAVA - mini 프로젝트 - 키오스크 만들기 (0) | 2023.06.11 |
JAVA - 실습5 - 메소드(Method) (0) | 2023.06.08 |
JAVA - 실습4 - 메소드(Method) (0) | 2023.06.08 |
댓글