반응형
package org.opentutorials.javatutorials.object;class Calculator{int left, right;public void setOprands(int left, int right){this.left = left;this.right = right;}public void sum(){System.out.println(this.left+this.right);}public void avg(){System.out.println((this.left+this.right)/2);}}public class CalculatorDemo4 {public static void main(String[] args) {Calculator c1 = new Calculator();c1.setOprands(10, 20);c1.sum(); c1.avg(); Calculator c2 = new Calculator();c2.setOprands(20, 40);c2.sum(); c2.avg();}}
추상적인 클래스 내에서 this. 은
사용자가 생성할 객체 안에서의 메소드를 가리킴
즉, this.left 라 함은,
Calculator c1 = new Calculator();
이라고 생성한 객체 c1의 속성값들을 접근하고자 할 때, 사용됨
반응형
'Programing > JAVA' 카테고리의 다른 글
| 다형성 (0) | 2017.11.22 |
|---|---|
| Public과 Private (0) | 2017.11.22 |
| 생성자와 객체 (0) | 2017.11.13 |
| 클래스, 객체, 메소드 (0) | 2017.11.13 |
| 객체지향 프로그래밍 (0) | 2017.11.12 |