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 |
Tags
- 인텔리제이
- java #중첩반복문 #구구단
- Arrays.toString()
- EffectiveJava
- 자바
- IntelliJ
- 자바 #JAVA
- 해쉬맵
- 람다
- java #조건문 #if조건문 #if
- HashMap
- 메서드
- overring
- 믹스인
- 자바 #변수 #java
- java #continue #반복문
- java # for문 #반복문
- java #객체지향 #자바
- java #자바 #상속
- java #자바 #상속 #오버라이딩
- 스프링 #Spring #spring #입문서
- 이펙티브자바
- java
- Math.sqrt()
- java #조건문 #if문
- Mixin
- Math.pow()
- 객체지향프로그램
- java #자료형
- 자바 #java #상속
Archives
- Today
- Total
산으로 가자▲
객체의 속성은 멤버 변수로, 객체의 기능은 메서드로 구현한다 본문
학생 클래스를 정의 하고 이를 사용해 보자
- 학생 클래스의 속성을 멤버 변수로 선언하고 메서드를 구현한다
`public class Student {
public int studentID;
public String studentName;
public String address;
public void showStudentInfo() {
System.out.println(studentName + "," + address);
}
public String getStudentName() {
return studentName;
}
}`
- 학생 클래스를 생성하여 생성된 객체(인스턴스)에 각각 다른 이름과 주소를 대입한다
`public class StudentTest {
public static void main(String[] args) {
Student studentLee = new Student();
studentLee.studentName = "이순신";
studentLee.address = "서울";
studentLee.showStudentInfo();
Student studentKim = new Student();
studentKim.studentName = "김유신";
studentKim.address = "경주";
studentKim.showStudentInfo();
System.out.println(studentLee);
System.out.println(studentKim);
}
}`
'Java' 카테고리의 다른 글
생성자에 대해 알아봅시다 (constructor) (0) | 2022.10.06 |
---|---|
인스턴스 생성과 힙 메모리 (heap memory) (0) | 2022.10.06 |
함수와 메서드 (1) | 2022.10.06 |
생활 속에서 객체 찾아 클래스로 구현해 보기 (0) | 2022.10.05 |
Math.Sqrt()란? (0) | 2022.10.05 |