삼성SDS_멀티캠퍼스/Java
-
9일 차 생성자의 정적변수 접근삼성SDS_멀티캠퍼스/Java 2015. 9. 17. 10:01
class Employee { private String name;private double salary; private static int count = 0; public String getName() {return name;} public void setName(String name) {this.name = name;} public double getSalary() {return salary;} public void setSalary(double salary) {this.salary = salary;} public static int getCount() {return count;} public static void setCount(int count) {Employee.count = count;} @O..
-
9일 차 정적변수삼성SDS_멀티캠퍼스/Java 2015. 9. 17. 09:31
class Car { private int speed;private int mileage;private String color;private int id;public static int numOfCars = 0; public int getSpeed() {return speed;} public void setSpeed(int speed) {this.speed = speed;} public int getMileage() {return mileage;} public void setMileage(int mileage) {this.mileage = mileage;} public String getColor() {return color;} public void setColor(String color) {this.c..
-
8일 차 시험(깊은 복사, 얕은 복사)삼성SDS_멀티캠퍼스/Java 2015. 9. 16. 16:57
class Score { private int eng;private int math;private int lang; public int getEng() {return eng;} public void setEng(int eng) {this.eng = eng;} public int getMath() {return math;} public void setMath(int math) {this.math = math;} public int getLang() {return lang;} public void setLang(int lang) {this.lang = lang;} @Overridepublic String toString() {return "Score [eng=" + eng + ", math=" + math ..
-
8일 차 중간점검(생성자)삼성SDS_멀티캠퍼스/Java 2015. 9. 16. 14:59
import java.util.Scanner; class Point { private int x;private int y; @Overridepublic String toString() {return "Point [x=" + x + ", y=" + y + "]";} public int getX() {return x;} public void setX(int x) {this.x = x;} public int getY() {return y;} public void setY(int y) {this.y = y;} public Point() { x = 10;y = 20;} public Point(int num, int num2) { Scanner scan = new Scanner(System.in); System.o..
-
8일 차 생성자 하나 만들어보기삼성SDS_멀티캠퍼스/Java 2015. 9. 16. 11:33
class Time { private int hour;private int minute;private int second; public int getHour() {return hour;} public void setHour(int hour) {this.hour = hour;} public int getMinute() {return minute;} public void setMinute(int minute) {this.minute = minute;} public int getSecond() {return second;} public void setSecond(int second) {this.second = second;} @Overridepublic String toString() {return Strin..
-
8일 차 생성자 생성시에 유의할 점 & 팁삼성SDS_멀티캠퍼스/Java 2015. 9. 16. 10:53
기본생성자가 매개변수를 가지고 있을때 new로 매개변수를 가지고 있지 않은 기본생성자를 호출하면 생성자를 찾을 수 없다는 에러가 뜬다. 그렇기 때문에 생성자를 호출할 때 유의 해야 한다. --------------------------------------------------------------------------- 이렇게 String만 가지고있는 생성자에 값을 넣는 방식으로 해도된다 하지만 더 좋은 방법이 있으니.... --------------------------------------------------------------------------- 모든 경우를 상정하고 최소한 생성자가 1개이상은 지나갈 수 있도록 생성자의 매개변수가 다른 경우를 한개씩 만들어버리는 것 출처: 삼성SDS멀티캠퍼..
-
8일 차 생성자는 메소드 오버로딩이 가능하다삼성SDS_멀티캠퍼스/Java 2015. 9. 16. 10:43
class Car { public int speed;public int mileage;public String color; // 생성자 호출public Car() {System.out.println("자동차가 만들어집니다")speed = mileage = 0;color = "red"; } public Car(int s, int m, String c) {speed = s;mileage = m;color = c; } public int getSpeed() {return speed;} public void setSpeed(int speed) {this.speed = speed;} public int getMileage() {return mileage;} public void setMileage(int mile..
-
8일 차 생성자삼성SDS_멀티캠퍼스/Java 2015. 9. 16. 10:24
객체가 생성될 때에 필드에게 초기값을 제공하고 필요한 초기화 절차를 실행하는 메소드 규칙1. 객체가 생성될때 한번 호출되는 메소드2. 메소드라서 오버로딩이 가능3. 일반적으로 수식어가 public (반환유형 자체가 없음)4. 함수명이 클래스명과 동일 class Car{public int speed;public int mileage;public String color;//생성자 호출 //--------------------------------------------------------------------------------------public Car(){System.out.println("자동차가 만들어집니다");color = "blue";} //-----------------------------..