Skip to content

Commit a662bcc

Browse files
committed
강의안 추가
1 parent 99d25a9 commit a662bcc

12 files changed

Lines changed: 249 additions & 1 deletion

File tree

StudyJavaExample/src/j_restriction/Restriction_1.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static void main(String[] args) {
1212
System.out.println(st1.a);
1313
Static st2 = new Static();
1414
System.out.println(st2.a);
15+
System.out.println(Static.a);
1516
}
1617

1718
}

StudyJavaExample/src/j_restriction/Restriction_2.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public class Restriction_2 {
1616
public static void main(String[] args) {
1717
// TODO Auto-generated method stub
1818

19+
Bank bk1 = new Bank();
20+
Bank bk2 = new Bank();
21+
bk1.printMoney(1000, 100);
22+
bk2.printMoney(0, 250);
23+
bk1.printMoney(0, 800);
1924
}
20-
2125
}
26+
27+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package k_constructor;
2+
3+
class Inherit{
4+
int a;
5+
Inherit(){
6+
a=1;
7+
}
8+
Inherit(int num){
9+
this.a = num;
10+
}
11+
}
12+
13+
public class Constructor_1 extends Inherit{
14+
int b;
15+
Constructor_1(int a, int b){
16+
super(a);
17+
this.b = b;
18+
}
19+
20+
public static void main(String[] args) {
21+
// TODO Auto-generated method stub
22+
23+
Constructor_1 ob = new Constructor_1(10,20);
24+
System.out.println(ob.a + " " + ob.b);
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package k_constructor;
2+
3+
class Calc{
4+
int x, y, sum;
5+
void set(int x, int y){
6+
this.x = x;
7+
this.y = y;
8+
}
9+
int GetSum(){
10+
return x+y;
11+
}
12+
void printData(){
13+
sum = GetSum();
14+
System.out.println("x =" + x + ", y = " + y);
15+
System.out.println("합 = " + sum);
16+
}
17+
}
18+
public class Constructor_2 {
19+
20+
public static void main(String[] args) {
21+
// TODO Auto-generated method stub
22+
Calc data = new Calc();
23+
data.set(10, 20);
24+
data.printData();
25+
}
26+
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package m_inheritance;
2+
3+
class Parent{
4+
int a;
5+
void print(){
6+
System.out.println("부모클래스입니다.");
7+
}
8+
}
9+
public class Inherit_1 extends Parent{
10+
11+
public static void main(String[] args) {
12+
// TODO Auto-generated method stub
13+
Inherit_1 ob = new Inherit_1();
14+
ob.a = 10;
15+
ob.print();
16+
}
17+
}
18+
19+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package m_inheritance;
2+
3+
class Parent2{
4+
int a;
5+
Parent2(){
6+
a = 10;
7+
System.out.println("부모 생성자 호출");
8+
}
9+
}
10+
public class Inherit_2 extends Parent2{
11+
12+
int b;
13+
Inherit_2(){
14+
// super(); <- 숨어 있다.
15+
b = 20;
16+
System.out.println("자식 생성자 호출");
17+
}
18+
public static void main(String[] args) {
19+
// TODO Auto-generated method stub
20+
Inherit_2 ob = new Inherit_2();
21+
System.out.println("a의 값 : " + ob.a);
22+
System.out.println("b의 값 : " + ob.b);
23+
}
24+
}
25+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package n_interface;
2+
3+
interface Hi{ // 인터페이스 Hi 정의
4+
void hi(); // 추상메서드 Hi() 선언
5+
}
6+
7+
interface Say extends Hi{ // 인터페이스 Hi를 상속받는 Say
8+
void say(); // 추상메서드 say()선언
9+
}
10+
11+
class Hey implements Say{ // 인터페이스 Say를 구현
12+
public void hi(){ // 추상메서드 hi() 오버라이딩
13+
System.out.println("안녕하세요.");
14+
}
15+
public void say(){ // 추상메서드 say() 오버라이딩
16+
System.out.println("잘 부탁드립니다.");
17+
}
18+
}
19+
20+
public class Interface_1 {
21+
22+
public static void main(String[] args) {
23+
// TODO Auto-generated method stub
24+
Hey h = new Hey();
25+
h.hi();
26+
h.say();
27+
}
28+
}
29+
30+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package n_interface;
2+
3+
interface My{
4+
void name();
5+
}
6+
public class Interface_2 implements My{
7+
8+
public static void main(String[] args) {
9+
// TODO Auto-generated method stub
10+
Interface_2 i = new Interface_2();
11+
System.out.print("My name is " );
12+
i.name();
13+
14+
}
15+
public void name(){
16+
System.out.println("popcorn");
17+
}
18+
}
19+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package p_polymorphism;
2+
3+
class Over{
4+
int a=10;
5+
}
6+
public class Polymorphism_1 extends Over{
7+
int a = 20; // 오버라이드
8+
void print(){
9+
System.out.println(super.a); // 부모로부터 물려받은 멤버, 10 출력
10+
System.out.println(this.a); // 자식이 다시 정의한 멤버, 20 출력
11+
}
12+
public static void main(String[] args) {
13+
// TODO Auto-generated method stub
14+
Polymorphism_1 ob = new Polymorphism_1();
15+
ob.print();
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package p_polymorphism;
2+
3+
class Over1{
4+
void hello(){
5+
System.out.print("Fun! ");
6+
}
7+
}
8+
public class Polymorphism_2 extends Over1{
9+
10+
void hello(){ // 오버라이드
11+
super.hello(); // 상속 받은 hello() 호출
12+
System.out.println("Java"); // 기능 확장
13+
}
14+
public static void main(String[] args) {
15+
// TODO Auto-generated method stub
16+
Polymorphism_2 ob = new Polymorphism_2();
17+
ob.hello();
18+
}
19+
}

0 commit comments

Comments
 (0)