Skip to content

Commit

Permalink
#26 클래스 메서드 실습
Browse files Browse the repository at this point in the history
  • Loading branch information
guddus326 committed Jul 1, 2021
1 parent be8423d commit 1d96f88
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions CSBasic5/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ namespace CSBasic5
{
class Program
{
public int instanceVariable = 10;
public int instanceMethod()
{
return 0;
}

class MyMath
{
public static int Abs(int input)
{
return (input < 0) ? -input : input;
/*
if(input < 0)
{
return -input;
}else
{
return input;
}*/
}
}

class Test
{
Expand Down Expand Up @@ -47,6 +68,17 @@ static void Main(string[] args)

Test test = new Test();
Console.WriteLine(test.Sum(1, 100));

Console.WriteLine(MyMath.Abs(52));
Console.WriteLine(MyMath.Abs(-273));

// 클래스 메서드에서는 인스턴스 변수/메서드 접근 불가!
// 객체를 만들어 접근해야한다.
//Console.WriteLine(instanceVariable);
//instanceMethod();
Program p = new Program();
Console.WriteLine(p.instanceVariable);
p.instanceMethod();
}
}
}

0 comments on commit 1d96f88

Please sign in to comment.