For faster navigation, this Iframe is preloading the Wikiwand page for 멤버 변수.

멤버 변수

객체 지향 프로그래밍에서 멤버 변수(member variable) 또는 멤버 필드는 특정 객체와 연결된 변수의 하나이며, 해당 변수의 모든 메소드(멤버 함수)에 접근이 가능하다. 클래스 기반 언어에서 이들은 두 종류로 구별된다: 모든 인스턴스의 클래스와 공유되는 변수의 사본이 하나만 있을 경우 이를 클래스 변수나 정적 멤버 변수로 부른다. 클래스의 각 인스턴스가 자신만의 변수 복사본을 소유하고 있는 경우 해당 변수는 인스턴스 변수라 부른다.[1]

예제

[편집]

C++

[편집]
#include <iostream>
class Foo {
    int bar; // 멤버 변수
  public:
    void setBar (const int newBar) { bar = newBar; }
};

int main () {
  Foo rect; // 지역 변수

  return 0;
}

자바

[편집]
class Program
{
    static void main(final String arguments[])
    {
    	// 이것은 로컬 변수이다. 이 변수의 수명은
    	// 어휘 범위에 의하여 결정된다.
    	Foo foo;
    }
}

class Foo
{
    // 이것은 멤버 변수이다. 이 변수의 새로운
    // 인스턴스는 Foo의 각각의 새로운
    // 인스턴스들을 위해 만들어진다. 이 변수의
    // 수명은 Foo의 "this" 인스턴스의 수명과
    // 동일하다.
    int bar;
}

같이 보기

[편집]

각주

[편집]
  1. Richard G. Baldwin (1999년 3월 10일). “Q - What is a member variable?”. http://www.dickbaldwin.com/: Richard G Baldwin Programming Tutorials. 2011년 8월 12일에 확인함. A member variable is a member of a class (class variable) or a member of an object instantiated from that class (instance variable). It must be declared within a class, but not within the body of a method of the class. 
{{bottomLinkPreText}} {{bottomLinkText}}
멤버 변수
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?