Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- react export default
- java
- 엔티티리슨너
- vscode 자동완성
- vscode snippets
- 영카드만사용하기
- entity jpa Listener
- 프런트앤드
- ERD #spring #spring-boot
- webpack
- 초보홈페이지도전기
- 스프링
- jpaRelationship
- 자바기본
- spring #entity #자바스프링 #스프링기초 #엔티티
- 1:1연관관계
- springboot
- 초보홈페이지
- 엔티티 기본 리스너
- react 기본문법
- Spring
- 이에스린트
- js slider
- 자바
- react export
- 스택틱
- webpack 설정
- java Throwable
- oneOnOneRelationship
- 스프링부트
Archives
- Today
- Total
디자인너 코딩하기
참조 자료형 변수 본문
개념
- 변수의 자료형
- 클래스형으로 변수를 선언
- 기본 자료형은 사용하는 메모리의 크기가 정해져 있지만, 참조 자료형은 클래스에 따라 다름
- 참조 자료형을 사용 할때는 해당 변수에 대해 생성하여야 함 예시 : new
(String 클래스는 예외적으로 생성하지 않고 사용할 수 있음)
public class Student {
int studentId;
String studentName;
Subject korea;
Subject math;
Student(int studentId, String studentName){
this.studentId = studentId;
this.studentName = studentName;
// 생성을 안해주면 메모리 한계(4바이트) 및 null point exception 일어날 수 있음
korea = new Subject();
math = new Subject();
}
public void setKoreaSubject(String name, int score){
korea.subjectName = name;
korea.score = score;
}
public void setMathSubject(String name, int score){
math.subjectName = name;
math.score = score;
}
public void showScoreInfo(){
int total = korea.score + math.score;
System.out.println(studentName + "학생의 총점은 " + total + "점입니다.");
}
}
반응형