Java (34) 썸네일형 리스트형 Day06 - 04 import java.util.Scanner; public class Oop5 { public static void main(String[] args) { Student1 stu= new Student1(); Scanner sc = new Scanner(System.in); System.out.println("몇 명의 학생을 등록할까요?"); int stu1=sc.nextInt(); Student1[] sts =new Student1[stu1]; for(int i=0; i Day06 - 03 public class Oop3 { public static void main(String[] args) { Fruit fruit1 = new Fruit(); fruit1.info(); fruit1.setName("사과"); fruit1.setPrice(1000); fruit1.setColor("red"); fruit1.setFrom("충주"); // fruit1.setSize("소과"); //자식에 추가된 필드를 수정할 수 없음 fruit1.info(); System.out.println(fruit1); Apple apple =new Apple(); apple.setName("사과"); // apple.setPrice(1000); apple.setColor("빨강"); apple.setFrom("충주".. Day06 - 02 public class Oop1 { public static void main(String[] args) { Student student1 = new Student(); //빈생성자 //참조변수가 가리킴 //타입이 클래스 student1.info(); //인스턴스 Student student2 =new Student(1,"김사과","010-1111-1111",90,80,100); //7.값입력 student2.info(); //넣은내용 출력 Student student3 =new Student(); student3.info(); student3.setNo(2); student3.setName("반하나"); student3.setHp("010-2222-2222"); //값 직접컨트롤x setter활용 st.. 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 - 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.. 이전 1 2 3 4 5 다음