본문 바로가기

Java 배우기145

Questions and Exercises: Classes Questions and Exercises: ClassesQuestionsConsider the following class:public class IdentifyMyParts { public static int x = 7; public int y = 3; } What are the class variables?What are the instance variables?What is the output from the following code:IdentifyMyParts a = new IdentifyMyParts(); IdentifyMyParts b = new IdentifyMyParts(); a.y = 5; b.y = 6; a.x = 1; b.x = 2; System.out.println("a.y = .. 2016. 1. 5.
Summary of Creating and Using Classes and Objects 클래스와 객체 만들기 및 사용하기 요약 Summary of Creating and Using Classes and Objects 클래스 선언은 클래스의 이름을 정호하고 괄호 사이에 클래스 몸체를 둘러쌉니다. 클래스 이름의 앞에는 modifier가 올 수 있습니다. 클래스 몸체에는 클래스의 필드, 메소드 및 생성자가 포함되어 있습니다. 클래스는 필드를 사용하여 상태 정보를 포함하고, 메소드를 사용하여 동작을 구현합니다. 클래스의 새 인스턴스를 초기화하는 생성자는 클래스 이름을 사용하고 리턴 타입이 없는 메소드 처럼 보입니다. A class declaration names the class and encloses the class body between braces. The class name can be .. 2016. 1. 5.
Initializing Fields 필드 초기화 하기 필드 초기화 하기 Initializing Fields 선언 안의 필드에 종종 초기 값을 제공할 수 있습니다. As you have seen, you can often provide an initial value for a field in its declaration:public class BedAndBreakfast { // initialize to 10 public static int capacity = 10; // initialize to false private boolean full = false; } 초기화 값을 사용할 수 있고 초기화를 한 줄에 넣을 수 있을 때 초기화는 잘 작동합니다. 하지만 이런 형태의 초기화는 단순하기 때문에 한계가 있습니다. 초기화가 어떤 논리를 필요로 하는 경우 (예,.. 2016. 1. 5.
Understanding Class Members 클래스 멤버에 대한 이해 클래스 멤버 이해하기 Understanding Class Members 이 섹션에서는, 클래스의 인스턴스가 아닌, 클래스에 속한 필드와 메소드를 생성하기 위한 키워드 static의 사용을 논의합니다. In this section, we discuss the use of the static keyword to create fields and methods that belong to the class, rather than to an instance of the class. 클래스 변수 Class Variables 많은 객체들이 동일한 클래스 청사진으로부터 생성될 때, 객체들 각각은 각자의 독특한 인스턴스 변수들의 카피를 갖게 됩니다. 클래스 Bicycle의 경우, 인스턴스 변수들은 cadence, gear.. 2016. 1. 5.
Controlling Access to Members of a Class 클래스 멤버들에 대한 접근 제어 클래스 멤버들에 대한 접근 제어 Controlling Access to Members of a Class 접근 수준 제한자는 다른 클래스가 특정 필드를 사용하거나 특정 메소드를 호출 할 수 있는지 여부를 결정합니다. 접근 제어에는 2가지 수준이 있습니다: Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:상단 수준에서 - public 또는 package-private (no explicit modifier). At the top level—public, or package-private.. 2016. 1. 5.
Using the this Keyword 키워드 this 사용하기 키워드 this 사용하기 Using the this Keyword 인스턴스 메소드나 생성자 안에서, this는 현재 객체(current object) (그 메소드나 생성자를 호출한 객체)에 대한 참조(reference) 입니다. 즉, this는 현재 객체 입니다. this를 사용하여 인스턴스 메소드나 생성자로부터, 또한 메소드나 생성자 안에서 현재 객체의 멤버를 참조(refer)할 수 있습니다. Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You can refer to any member of .. 2016. 1. 5.