본문 바로가기
카테고리 없음

project X) 2주차 과제 메모

by 농농씨 2024. 5. 21.

상속

super

다단계상속 계층적 상속

다중상속 제외

https://coding-factory.tistory.com/865

 

오류: There is no default constructor available in

https://velog.io/@gywns0417/Java-Error-there-is-no-default-constructor-available-in-%EC%83%81%EC%86%8D

 

Java - (Error) There is no default constructor available in (상속)

(Error) There is no default constructor available in

velog.io

 

super() 안에 부모함수의 생성자 모두 넣어줘야함 

 

override 원리

https://velog.io/@jonghyun3668/%EC%9E%90%EB%B0%94%EC%97%90%EC%84%9C-%EC%98%A4%EB%B2%84%EB%9D%BC%EC%9D%B4%EB%93%9COverride%EC%9D%98-%EC%9B%90%EB%A6%AC

 

자바에서 오버라이드(Override)의 원리

오버라이드(재정의)는 어떤식으로 작동하는 걸까요? 원리에 대해 알아봅시다!

velog.io

 

하위클래스의 필드 출력하기

https://nittaku.tistory.com/87

 

15. 상속과 super - (자식클래스가 부모의 필드까지 이용하기) [Tutorial15]

미리 만든 [Person - 이름, 키, 나이, 몸무게 ]클래스를 상속하면, 아래 자식클래스들[ Student - 학점, 학번, 학년 + (상속)이름, 키,나이,몸무게 ] , [ Teacher - 교직원 번호, 월급, 년차 + (상속)이름, 키,나

nittaku.tistory.com

 

 

클래스 확인하기 조건문

https://ko.javascript.info/instanceof

 

'instanceof'로 클래스 확인하기

 

ko.javascript.info

 

https://velog.io/@hkoo9329/%EC%9E%90%EB%B0%94-extends-implements-%EC%B0%A8%EC%9D%B4

 

자바 extends, implements 차이

상속이란 (Inheritance) 상속을 말하기 전에 먼저 OOP가 무엇인지 알면 좋을거 같다.OOP(Object-Oriented Programming, 객체 지향 프로그래밍) 이란? OOP의 특징으로 1. 상속과 인터페이스 (계층성) 2. 다형성, 사

velog.io

class 를 상속받을 때는 extends

인터페이스를 상속받을 때는 implements

전자를 상속받을 때는 일부만 구현해도 되고

후자는 다 구현해야 한다.

 

https://st-lab.tistory.com/153

 

자바 [JAVA] - 제네릭(Generic)의 이해

정적언어(C, C++, C#, Java)을 다뤄보신 분이라면 제네릭(Generic)에 대해 잘 알지는 못하더라도 한 번쯤은 들어봤을 것이다. 특히 자료구조 같이 구조체를 직접 만들어 사용할 때 많이 쓰이기도 하고

st-lab.tistory.com

 

 

 

public class RuleOfBiodome04 {
    public static void main(String[] args) {

        // 동물, 식물, 미생물 객체 생성
        AnimalFeature animal1 = new AnimalFeature("귀여움", "포유류", "20년");
        AnimalFeature animal2= new AnimalFeature("얼룩말", "동물", "잘 달린다, 포유류, 10년");
        PlantFeature plant1= new PlantFeature("보라색", "열매 없음", "7월");
        PlantFeature plant2= new PlantFeature("분홍색", "열매 있음", "3월");
        MicrobeFeature microbe1= new MicrobeFeature("호흡 및 발효 대사","약산성");
        MicrobeFeature microbe2= new MicrobeFeature("호흡 대사", "약산성");

        BiologicalEntity<Feature> cat = new BiologicalEntity<>("고양이", "동물", animal1);
        BiologicalEntity<Feature> zebra = new BiologicalEntity<>("얼룩말", "동물", animal2);
        BiologicalEntity<Feature> rosemary = new BiologicalEntity<>("로즈마리", "식물", plant1);
        BiologicalEntity<Feature> blossom = new BiologicalEntity<>("벚꽃", "식물", plant2);
        BiologicalEntity<Feature> ecol = new BiologicalEntity<>("이콜라이", "미생물", microbe1);
        BiologicalEntity<Feature> bacill = new BiologicalEntity<>("바실러스", "미생물", microbe2);



        // BiologicalSystem 객체 생성 및 생물 정보 추가
        BiologicalSystem<Feature> system = new BiologicalSystem<>();
        system.add(cat);
        system.add(zebra);
        system.add(rosemary);
        system.add(blossom);
        system.add(ecol);
        system.add(bacill);

        // 가장 최근에 등록된 생물 정보 삭제 및 출력
        system.delete();
        system.show();

        // 생물 정보 리스트가 비어있는지 확인
        system.isEmpty();
        system.clear();
    }

}

 

interface Feature { // 타입 상관없이 생성(껍데기)

}
public class BiologicalEntity<T> {
    private String name; // 이름
    private String sort; // 분류

    private T feature; // 종별 특징

    // 생성자
    public BiologicalEntity(String name, String sort, T feature) {
        this.name = name;
        this.sort = sort;
        this.feature = feature;
    }
    // getter, setter
    public String getName() {
        return name;
    }
    // toString 메서드
    @Override
    public String toString() {
        return ","+sort+","+feature.toString();
                //name + ", " + sort + ", " + feature.toString();
    }

//    <S> void genericMethod(S o) {// [접근 제어자] <제네릭타입> [반환타입] [메소드명]([제네릭타입] [파라미터])
//        // 제네릭 함수
//        // - 클래스에서 지정한 제네릭유형과 별도로 메소드에서 독립적으로 제네릭 유형을 선언하여 쓸 수 있다
//        // 제네릭이 사용되는 메소드를 정적메소드로 두고 싶은 경우 제네릭 클래스와 별도로 독립적인 제네릭이 사용되어야 한다
//        return;
//    }
}
class AnimalFeature implements Feature {
    String species, feature, lifespan;
    public AnimalFeature(String species, String feature, String lifespan) {
        this.species=species;
        this.feature=feature;
        this.lifespan=lifespan;
    }
    public String toString() {
        return species+","+feature+","+lifespan;
    }
}
class PlantFeature implements Feature{
    String color, fruit, flowering;
    public PlantFeature(String color, String fruit, String flowering) {
        this.color=color;
        this.fruit=fruit;
        this.flowering=flowering;
    }
    public String toString() {
        return color+","+fruit+","+flowering;
    }
}
class MicrobeFeature implements Feature{
    String metabolism, environment;
    public  MicrobeFeature(String metabolism, String environment) {
        this.metabolism=metabolism;
        this.environment=environment;
    }
    public String toString() {
        return metabolism+","+environment;
    }
}
import java.util.ArrayList;
import java.util.List;

public class BiologicalSystem<T> {
    public List<BiologicalEntity<T>> entities;
    public BiologicalSystem() {
        entities=new ArrayList<>();
    }
    // 새로운 생물 정보 추가
    public void add(BiologicalEntity<T> entity) {
        entities.add(entity);
        System.out.println("새로운 생물이 등록되었습니다 : " + entity.getName());
    }
    public void delete() {
        if (!entities.isEmpty()) { // 리스트가 비어있지 않을 때 실행
            BiologicalEntity<T> entity = entities.remove(entities.size() - 1);
            System.out.println("생물이 삭제 되었습니다 : " + entity.getName());
        } else {
            return;
        }
    }
    public void clear() {
        entities.clear();
        System.out.println("모든 정보를 삭제했습니다.");
    }
    public void show() {
        if (!entities.isEmpty()) {
            System.out.println("최신 등록 생물 : "+ entities.get(entities.size() - 1).getName());
        } else {
            System.out.println("없습니다.");
        }
    }
    public void isEmpty() {
        if (entities.isEmpty()) {
            System.out.println("생물 정보 리스트는 비어있습니다.");
        } else {
            System.out.println("생물 정보 리스트가 비어있지 않습니다.");
        }
    }

    public void sortByName() {

    }
}
class Comparable {

}