티스토리 뷰

JAVA

생성자 구현하기

코린이도이 2023. 9. 19. 09:53

1. String형 변수 name을 매개 변수로 받는 생성자 Student를 작성하세요.

class Student {
	String name
    void study() {
    	System.out.println(name + " Studying");
    }
    Student(String name) {
    	this.name = name;
    }
}

public class Main {
	public static void main(String args[]) {
    	Student student = new Student("Elice");
        student.study();
    }
}

'JAVA' 카테고리의 다른 글

static 변수  (0) 2023.09.19
생성자 오버로드  (0) 2023.09.19
생성자  (0) 2023.09.19
인스턴스 사용하기  (0) 2023.09.19
클래스 만들어보기(2)  (0) 2023.09.19
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함