# 6 장 . 클래스 : 속성

• View
60

0

Embed Size (px)

DESCRIPTION

6 . : . Java. public class SumTest { public static void main(String a1[]) { int a, b, sum; a = Integer.parseInt (a1[0]); b = Integer.parseInt (a1[1]); sum = a + b ; // System.out.println (" " + sum + " "); } - PowerPoint PPT Presentation

Transcript

PowerPoint Presentation

6. : 1public class SumTest { public static void main(String a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // System.out.println(" " + sum + ""); }}Java12 2section 1 section 2 section 3 section 4 4-1 4-2 4-3 (final) 4-4 section 5 5-1 public 5-2 private 5-3 section 6 (Scope) 3 31-1 1 4 ( ) 187page

6. : 4 1 5Box_Sample.java0102030405060708091011121314151617public class Box_Sample { int width; int height; int depth; int volume; Box_Sample(int w, int h, int d) { width = w; height = h; depth = d; } int volume_compute() { volume = width * height * depth; return volume; }}6. : 5 2 6

Public : : Final : (abstract) :

[public/final/abstract] class Class-name {.................. .........}6. : 6 2 7 class Box { int width; int height; int depth;}6. : 7 2 8 class Box { int width; int height; int depth; public void volume() { int vol; vol = width * height * depth; System.out.println("Volume is "+vol); }}6. : 8 2 9, , class Box { int width; int height; int depth; public void Box(int w, int h, int d) { width=w; height=h; depth=d; } public void volume() { // int vol; vol = width * height * depth; System.out.println("Volume is "+vol); }}6. : 9 3 10

;Box mybox1;Avg student1;String name;6. : 10 3 11 =new;Box mybox1;mybox1 = new Box(10,20,30);6. : 11 3 12 =new();Box mybox1 = new Box(10, 20, 30);Avg student1 = new Avg();String name = new String("");6. : 12 3 13 class Box { int width; int height; int depth;}class MyBox {............ Box mybox1; Box mybox2; mybox1 = new Box(); mybox2 = new Box();.............

193 page6. : 13 3 14Box1Test.java010203040506070809101112131415161718class Box1 { int width; int height; int depth;}public class Box1Test { public static void main(String args[]) { Box1 mybox1 = new Box1(); Box1 mybox2 = new Box1(); int vol1, vol2;

mybox1.width = 20; mybox1.height = 40; mybox1.depth = 15;

mybox2.width = 10; mybox2.height = 20; mybox2.depth = 30;Box16. : 14 3 15Box1Test.java1920212223242526 vol1 = mybox1.width * mybox1.height * mybox1.depth; System.out.println(" " + vol1 + ".");

vol2 = mybox2.width * mybox2.height * mybox2.depth; System.out.println(" " + vol2 + "."); }}6. : 15 3 16 01 :Box1.08~09 :Box1.12~18 :.20~24 :.

6. : 16 4 17

[public/private][static/final];196 page6. : 174-1 4 18 ............int my_count1 = 100;int my_count2 = my_count1;Box mybox1 = new Box();Box mybox2 = mybox1;............6. : 184-1 4 19

198 page6. : 194-1 4 20Box2Test.java010203040506070809101112131415class Box2 { int width=10; int height=20; int depth=30;}public class Box2Test { public static void main(String args[]) { int myint1 = 100; int myint2 = myint1; System.out.println(" : " + myint1 + " : " + myint2); myint1 = 200; System.out.println(" : " + myint1 + " : " + myint2); Box2 mybox1 = new Box2();6. : 204-1 4 21Box2Test.java16171819202122232425262728 Box2 mybox2 = mybox1; mybox1.width = 20; System.out.println("mybox1.width : " + mybox1.width); System.out.println("mybox2.width : " + mybox2.width); mybox2.depth = 123; System.out.println("mybox1.depth : " + mybox1.depth); System.out.println("mybox2.depth : " + mybox2.depth); }}mybox1widthmybox2depth6. : 214-1 4 22 02~04 :,.08~12 :.13~26 :,.,.

6. : 224-2 4 23 static (global variable) static;static long boxid;static double degree;6. : 234-2 4 24

201 page6. : 244-2 4 25Box3Test.java01020304050607080910class Box3 { int width; int height; int depth; long idNum; static long boxID = 0; public void increment() { idNum = ++boxID; }}6. : 254-2 4 26Box3Test.java111213141516171819202122232425262728class Box3Test { public static void main(String args[]) { Box3 mybox1 = new Box3(); Box3 mybox2 = new Box3(); Box3 mybox3 = new Box3(); Box3 mybox4 = new Box3(); mybox1.increment(); mybox2.increment(); mybox3.increment(); mybox4.increment(); System.out.println("mybox1 id : " + mybox1.idNum); System.out.println("mybox2 id : " + mybox2.idNum); System.out.println("mybox3 id : " + mybox3.idNum); System.out.println("mybox4 id : " + mybox4.idNum); System.out.println(" " + Box3.boxID + "."); }}6. : 264-2 4 27 06 :..26 :.

6. : 274-3 (final) 4 28 final final=;final int MAX =100;final int MIN = 1;6. : 284-4 4 29 .

.or.6. : 294-4 4 30 .class A { int aa; int bb; int cc; static int s = 0;}class ATest { public static void main(String args[]) { A obja = new A(); obja.aa = 4; obja.bb = obja.aa * 2; obja.cc = A.s; ....................6. : 305-1 public5 31

public class Box3 { public int width; public int height; public int depth; public long idNum; static long boxID = 0; public void increment() { idNum = ++boxID; }} .................. Box3 mybox1 = new Box3(); mybox1.width = 7; mybox2.depth = 20; ...............6. : 315-2 private5 32private class Box3 { private int width; private int height; private int depth; private long idNum; static long boxID = 0; public void increment() { idNum = ++boxID; }}

.................. Box3 mybox1 = new Box3(); mybox1.width = 7; mybox2.depth = 20; ...............6. : 325-3 5 33 6. : 33 6 (Scope)34

(exception handler parameter)

6. : 34 6 (Scope)35

207 page6. : 35 + . ( ) .

. , .

. new . 3636 , , . . . . . , . , .

3737 .public . public .private . .

. 38386. : 39. ?39