전체 글 (229) 썸네일형 리스트형 8.3 Field Declarations (2) 8.3.1 Field Modifiers 8.3.1.1 static Fields 결과: (2, 2) 0 true 1 Example 8.3.1.1-2. Hiding of Class Variables package main; public class Test extends Point { static double x = 4.7; public static void main(String[] args) { new Test().printX(); } void printX() { System.out.println(x + " " + super.x); } } class Point { static int x = 2; } 결과: 4.7 2 Test 클래스의 x의 선언은 Point 클래스의 x의 정의를 숨기기 때문에, Test 클래.. 8.3 Field Declarations (1) Example 8.3-1. Multiply Inherited Fields A class may inherit two or more fields with the same name, either from two interfaces or from its superclass and an interface. A compile-time error occurs on any attempt to refer to any ambiguously inherited field by its simple name. A qualified name or a field access expression that contains the keyword super (§15.11.2) may be used to access such fields .. [자바] 8.2 클래스 멤버 Example 8.2-1. Use of Class Members package classmember; /** * 8.2-1 클래스 멤버의 사용 * @author DELL * */ public class Test { public static void main(String[] args) { ColoredPoint c = new ColoredPoint(); // error c.reset(); // error } } class Point { int x, y; private Point() { reset(); } Point(int x, int y) { this.x = x; this.y = y; } private void reset() { this.x = 0; this.y = 0; } } class ColoredPo.. 이전 1 ··· 21 22 23 24 25 26 27 ··· 77 다음