접근제어자 클래스이름(파라미터) {
...
}
new Car();
new
키워드와 함께 생성자를 호출할 수 있음 public Student(){}
Human.java
public class Human {
public String name;
public int age;
public int weight;
public int height;
public Human(String name, int age, int weight, int height) {
this.name = name;
this.age = age;
this.weight = weight;
this.height = height;
}
public String info() {
return "이름 : "+name+" / 나이 : " + age + " / 키 : "+height+" / 몸무게 : "+ weight;
}
}
God.java
public class God {
public static void main(String[] args) {
//Human khw = new Human();
Human khw = new Human("김현욱", 32, 180,80);
String data = khw.info;
System.out.println(data);
}
}
JAVA - Basic_05 클래스(Class) (0) | 2021.04.01 |
---|---|
JAVA - Basic_04 반복문 (0) | 2021.03.31 |
JAVA - Basic_03 조건문 (0) | 2021.03.29 |
JAVA - Basic_02 연산자(Operator) (0) | 2021.03.26 |
JAVA - Basic_01 변수 (0) | 2021.03.25 |
댓글 영역