Java로 배우는 객체 지향 프로그래밍 입문
Sani Yusuf
Lead Software Engineering Content Developer


// Car class class Car { String model; // Property for model of carint topSpeed; // Property for car's top speed boolean isInsured; // Property for current insurance state }
class Passport {
String firstName; // Passport holder's first name
String lastName; // Passport holder's last name
Passport() {
// Constructor of Passport class
}
}
class Passport {
String firstName; // Passport holder's first name
String lastName; // Passport holder's last name
Passport() {
this.firstName = "David"; // 생성자에서 속성 설정
this.lastName = "Beckham";
}
}
class Passport {
String firstName;
String lastName;
// Constructor with parameters
Passport(String firstName, String lastName) {
}
}
this 키워드는 Passport 객체를 가리킵니다
class Passport {
String firstName;
String lastName;
Passport(String firstName, String lastName) {
this.firstName = firstName; // 생성자 매개변수로 속성 설정
this.lastName = lastName; //
}
}
new 키워드로 생성합니다
// Passport Class with constructor
class Passport {
String firstName;
String lastName;
// Constructor method
Passport(String firstName,
String lastName){
this.firstName = firstName;
this.lastName = lastName;
}
}
// Main Class
public class Main {
// main method (program entry point)
public static void main(
String[] args) {
// Passing parameters to constructor
// Passport(firstName, lastName)
Passport myPassport =
new Passport("Michael","Jackson");
System.out.println(
myPassport.firstName); // Michael
}
}
Java로 배우는 객체 지향 프로그래밍 입문