전체 글 (104) 썸네일형 리스트형 Day06 - 01 public class Fruit { private String name; private int price; //private setter getter필요 private String color; private String from; public Fruit(){} //생성자 public Fruit(String name, int price, String color, String from) { this.name = name; this.price = price; this.color = color; this.from = from; } public String getName() { return name; } public void setName(String name) { this.name = name; } publi.. Day06 1. 객체의 배열 클래스이름 참조변수 =new 클래스이름[요소의갯수]; ex) 데이터타입(int) [] arr =new int[3]; //배열 x arr[0] =10; Student[] arr = new Student[3]; //배열만든것 student가 저장할공간 3개를 만든것 객체 아직x!! //배열을 객체 찍어 저장 //arr==참조변수 3개를 만들 배열을 저장 객체만들기(Student) Student[] arr = new Student[3]; //배열3개를 만들어서 0 1 2 arr변수가 배열 가리킴 -> ★arr[0] = new Student(); //객체의0번방에 객체찍음 //배열의0번째방에 객체찍음 arr[0].setNo(1); //0번방 0번 arr[0].setName("김사과"); //0.. Day05 - 4 public class Samsungfan { //프라이빗 접근불가 현재 클래스의{} 바깥쪽에서는 절대 접근하거나 호출할 수 없음, 그래서 접근하기위해 객체를찍어서 불러온다?? private static int serialnumber; //시리얼번호 private String name; // 선풍기품명("SSEDA"+색상+시리얼번호) private String color; //선풍기색상 private String rotation; //회전여부(기본값:고정) private int level;//강도(기본값:1,max:3) private String power; //전원여부(기본값:off) Samsungfan(){ //빈 생성자를 출력하면 color white가 출력 this("white");} //기본생성.. Day5 - 03 public class Student { private int no; private String name; private String hp; private String address; private String blood; private String mbti; public int getNo() { return no; } public void setNo(int no) { this.no = no; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getHp() { return hp; } public void setHp(String hp) { this.hp = .. Day5 - 02 public class User { String id; String name; String password; int age; double point; // 생성자 User(){ //생성자 값 System.out.println("✌"); id = "no_id"; name = "무명"; password = "0000"; age = 0; point = 0; } User(String id, String name){ this(id, name,"😊",100,100000); } //타입(String2개)와 변수갯수 2개 를 출력하면()가 출력 User(String id, String name, String password, int age, double point){ //오버로딩???같은 클래스내 생성자 또는 메소드 .. Day5 - 01(Method) public class Main1{ public static void main(String[] args){ System.out.println("Hello World!"); for(String str : args){ System.out.print(str + " "); } } } public class Method1 { // 객체를 생성해서 사용해야 함 // public void method2(){ // System.out.println("Hello Java!"); // } // public static void method1(){ System.out.println("Hi"); } public static void main(String[] args) { // Method1 method1 = new Metho.. Day5 1. 메소드(method) - 어떤 로직이나 기능을 만들어 내는 방법(함수) - 코드를 재활용 할 수 있도록 하여 경제적으로 코드를 작성할 수 있음 - 객체를 생성하여 참조변수를 통해 호출할 수 있는 함수 *개념설명시 [ ]는 있어도 되고 없어도 되는값 접근제어자 [static] 반환타입 메소드이름([매개변수1, 매개변수2 ..]){ 메소드이름이 호출되면 실행할 문장; ... [return 반환값] } // static 이 붙으면 객체생성 필요X , static이 없으면 객체생성해서 사용해야함 public static int sum(int num1, int num2){ int tot = num1 + num2; return tot; } int result = sum(10,5); - 이름만 호출하면 실행되는.. Day4 - String 클래스! 타입x 2. String클래스 자바의 문자열을 저장하고 다룰 수 있는 클래스 👍String 클래스는 불변객체! 객체만들면 새로운 저장공간으로 만듬 String st3 ="apple"; ->값을 바꿀때마다 전에 만들어둔 공간이 계속쌓인다. 그리고 새로운 객체를 계속만들어준다. for문안에서 사용할 때 조심 char[] ch ={'안','녕','하','세','요'}; --> 불편해결 String String str = new String("안녕하세요"); String str = "안녕하세요"; 예제 public class String1 { public static void main(String[] args) { String str1 = new String("apple"); String str2 = new Strin.. 이전 1 ··· 5 6 7 8 9 10 11 ··· 13 다음