[Java Programming] Java return, 자바 리턴값 배우기


[Person.java]


class Person{

String name = "Lin";

String bloodType;

int age = 20;


void speak(){

System.out.println("저의 이름은"+name+"이고 혈액형은"+bloodType+"입니다.");

}

String getName(){

return name;

}


int getAge(){

return age;

}

}


[Application.java]


public class Application{

public static void main(String[] agrs){

Person person1 = new Person();

String myName = person1.getName();

int myAge = person1.getAge() + 6;

System.out.println(myAge);

}

}


[result]

26

+ Recent posts