๋ฐ์ํ
*ํด๋์ค๋?
package classpart;
public class classStudent { // class=ํด๋์ค๋ฅผ ๋ง๋๋ ์์ฝ์ด, classStudent=ํด๋์ค ์ด๋ฆ
// ๋ฉค๋ฒ ๋ณ์
int studentID;
String studentName;
int grade;
String address;
}
*Person ํด๋์ค ๋ง๋ค๊ธฐ
package classpart;
public class Person {
String name;
int height;
double weight;
char gender;
boolean married;
}
*ํ์ ์ด๋ฆ๊ณผ ์ฃผ์ ์ถ๋ ฅํ๋ ๋ฉ์๋ ๋ง๋ค๊ธฐ
package classpart;
public class Student {
int studentID;
String studentName;
int grade;
String address;
public void showStudentInfo() { // ๋ฉ์๋ ์ถ๊ฐ
System.out.println(studentName + "," + address); // ์ด๋ฆ, ์ฃผ์
}
}
*์ฌ์น ์ฐ์ฐ ํจ์ ๊ตฌํํ๊ธฐ
public static int add(int n1, int n2) {
int result = n1 + n2;
return result;
}
public static int sub(int n1, int n2) {
int result = n1 - n2;
return result;
}
public static int gob(int n1, int n2) {
int result = n1 * n2;
return result;
}
public static int div(int n1, int n2) {
int result = n1 / n2;
return result;
}
*์ฌ์น์ฐ์ฐ์ ์ค์๊ฐ์ผ๋ก ์ถ๋ ฅ๋๊ฒ ํ๊ธฐ
public static double div(int n1, int n2) {
double result = (double) n1 / n2;
return result;
}
๋ฐ์ํ
'Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] ํด๋์ค์ main( ) ํจ์ ํฌํจํ๊ธฐ (0) | 2021.02.18 |
---|---|
[Java] ํด๋์ค ๊ธฐ๋ฅ์ ๊ตฌํํ๋ ๋ฉ์๋ (0) | 2021.02.17 |
[Java] ์ฌํ ๋ฌธ์ (0) | 2021.02.16 |
[Java] ์ค์ต (0) | 2021.02.16 |
[Java] ์ฌํ์์ (0) | 2021.02.16 |
๋๊ธ