728x90 전체 글399 [JAVA] ch07-08. 객체 지향 8 public class Ex08 { public static void main(String[] args){ Paper paper = new Paper(10, "HEART"); //paper.NUMBER = 5; System.out.println(paper.NUMBER); System.out.println(paper.KIND); } } //public 메서드호출 //private 멤버변수 class Paper{ final int NUMBER; final String KIND; static int width = 100; static int height = 250; Paper(){ this(1,"HEART"); } Paper(int number, String kind){ this.NUMBER = number;.. JAVA/예제 2017. 8. 22. [JAVA] ch07-06. 객체 지향 6 //import 패키지.클래스 // import 패키지.*;은 가독성이 떨어짐 //import java.lang.*; 생략된 import문 컴파일러가 자동으로 추가 시켜줌 public class Ex06 { public static void main(String[] args){ Point3D point = new Point3D(); System.out.printf("(%d, %d, %d)",point.x,point.y,point.z); } } class Point3D extends Point{ //Object는 최상위클래스 int z = 30; Point3D(){ this(100,200,300); } Point3D(int x, int y, int z){ super(x,y); this.z = z; } } .. JAVA/예제 2017. 8. 22. [JAVA] ch07-05. 객체 지향 5 public class Ex05 { public static void main(String[] args){ Descendant descendant = new Descendant(); descendant.method(); } } class Descendant extends Parent{ int x = 20; void method(){ System.out.println("x= "+x); System.out.println("this.x= "+this.x); System.out.println("super.x= "+super.x); } } JAVA/예제 2017. 8. 22. [JAVA] ch07-04. 객체 지향 4 public class Ex04 { public static void main(String[] args){ Child child = new Child(); child.method(); } } class Parent{ int x =10; } class Child extends Parent{ void method(){ System.out.println("x= "+x); System.out.println("this.x= "+this.x); System.out.println("super.x= "+super.x); } } JAVA/예제 2017. 8. 22. [JAVA] ch07-03. 객체 지향 3 public class Ex03 { public static void main(String[] args){ TVCR tvcr = new TVCR(); tvcr.power(); tvcr.play(); tvcr.stop(); System.out.println(tvcr); } } class TVCR extends Tv{ VCR vcr = new VCR(); int counter = vcr.counter; void play(){vcr.play();} void stop(){vcr.stop();} void rew(){vcr.rew();} void ff(){vcr.ff();} } class Tv{ boolean power; int channel; void power(){power = !power;} void chan.. JAVA/예제 2017. 8. 22. [JAVA] ch07-02. 객체 지향 2 public class Ex02 { public static void main(String[] args){ Deck deck = new Deck(); Card card = deck.pick(0); System.out.println(card); deck.shuffle(); card = deck.pick(0); System.out.println(card); } } class Card{ static final int KIND_MAX = 4; //final을 변수에 쓰게되면 상수화. static final int NUM_MAX = 13; static final int SPADE = 4; static final int DIAMOND = 3; static final int HEART = 2; static final.. JAVA/예제 2017. 8. 22. [JAVA] ch07-01. 객체 지향 public class Ex01{// 모든클래스는 상속되어있다. public class Ex01 extends Object 생략됨 public static void main(String[] args){ Ex01 e = new Ex01(); e.paint(); } void paint(){ Point[] p = {new Point(100,100), new Point(140,50), new Point(200,100)}; Triangle t = new Triangle(p); Triangle tp = new Triangle(new Point(100,100), new Point(140,50), new Point(200,100)); Circle c = new Circle(new Point(150,150), 50); .. JAVA/예제 2017. 8. 22. [JAVA] ch06-10. 배열 (Array) 10 public class Ex10 { public static void main(String[] args){ char[] abc = {'A','B','C','D'}; char[] number = {'0','1','2','3','4','5','6','7','8','9'}; System.out.println(new String(abc)); System.out.println(new String(number)); char[] result = new char[abc.length+number.length]; System.arraycopy(abc, 0, result, 0, abc.length);//abc의 0번째부터 abc length만큼 result 0번에다가 붙여넣기 System.arraycopy(number, 0.. JAVA/예제 2017. 8. 22. [JAVA] ch06-09. 배열 (Array) 9 public class Ex09 { public static void main(String[] args){ int[] source = {1,2,3,4,5}; int[] target = new int[10]; for(int i=0; i JAVA/예제 2017. 8. 22. [JAVA] ch06-08. 배열 (Array) 8 public class Ex08 { //다차원 배열 아파트를 연상하라.성적표 public static void main(String[] args){ int[][] score = { // 2차원 배열 {100, 100, 100}, {100, 20, 20}, {30, 30, 30}, {40, 40, 40}, {50, 50, 50}, }; int korTot=0, engTot=0, mathTot=0; System.out.println("num kor eng math total avg"); System.out.println("=========================="); for(int i=0; i JAVA/예제 2017. 8. 22. [JAVA] ch06-07. 배열 (Array) 7 public class Ex07 { //16진수를 2진수로 public static void main(String[] args){ char[] hex = {'7', 'C', 'A', 'F', 'E'}; String[] binary = { // 0 1 2 3 16진수 "0000", "0001", "0010", "0011", // 4 5 6 7 "0100", "0101", "0110", "0111", // 8 9 A B "1000", "1001", "1010", "1011", // C D E F "1100", "1101", "1110", "1111", }; String result = ""; for(int i=0; i='0' && hex[i] JAVA/예제 2017. 8. 22. [JAVA] ch06-06. 배열 (Array) 6 public class Ex06 { public static void main(String[] args){ int[] number = new int[10]; int[] counter = new int[10]; for(int i=0; i JAVA/예제 2017. 8. 22. 이전 1 ··· 20 21 22 23 24 25 26 ··· 34 다음 728x90