오버라이딩과 추상화의 차이점은 > 오버라이딩: 서브클래스에서 부모클래스 메소드의 쓰임을 변경하고자 할 때 쓰입니다. 이 때 주의할 점은 리턴타입, 메소드명, 파라미터 타입이 반드시 똑같아야 한다. abstract : 보통 추상클래스나 추상 메서드라고 선언할 때 쓰인다. 추상클래스는 객체를 생성할 수 없습니다. 추상 메서드는 이러한 메서드를 사용할꺼다 라고 리턴타입과 메서드명 그리고 파라미터만 명시할 뿐이고 직접적인 구현은 이 추상 메서드를 상속받은(추상메서드를 가지는 클래스는 반드시 추상 클래스입니다) 서브 클래스에서 하게 됩니다. 결과적으로 오버라이딩 : 부모쪽에서 메소드를 선언한 것을 자식 클래스에서 extends (상속)받아 그 부모 메소드를 재정의(오버라이딩) 하여 자식 고유의 메소드로 만드는 것..
앞서, 복제란것이 이해하기 쉽고 연관되어있다. 데이터들은 기본적으로 제공된다해서 기본 데이터 타입이다ex) byte short int long 기본데이터 타입이 아닌것은ex)데이터타입을 생성할때 new를 통해서 생성하는것들은 기본데이터 타입이아ㄹ니라 참조형데이터 형이다참조가 들어간다 참조의 예로 class A{ public int id; A(int id){ this.id = id; }}public class ReferenceDemo1 { public static void runValue(){ int a = 1; int b = a; b = 2; System.out.println("runValue, "+a); } public static void runReference(){ A a = new A(1); A ..
enum은 열거형이라고 부른다 열거형은 서로 연관된 상수들의 집합니다.즉, enum=서로 연관된 상수들의 집합. enum Fruit{ APPLE, PEACH, BANANA;}enum Company{ GOOGLE, APPLE, ORACLE;} public class ConstantDemo { public static void main(String[] args) { /* if(Fruit.APPLE == Company.APPLE){ System.out.println("과일 애플과 회사 애플이 같다."); } */ Fruit type = Fruit.APPLE; switch(type){ case APPLE: System.out.println(57+" kcal"); break; case PEACH: System.o..
clone = 복제라는 뜻 어떤 객체가 있을때 그 객체를 똑같이 복제해주는 역할. class Student implements Cloneable{ String name; Student(String name){ this.name = name; } protected Object clone() throws CloneNotSupportedException{ return super.clone(); }} class ObjectDemo { public static void main(String[] args) { Student s1 = new Student("egoing"); try { Student s2 = (Student)s1.clone(); System.out.println(s1.name); System.out...
ex) public static void main(String[] args) { Student s1 = new Student("egoing"); Student s2 = new Student("egoing"); System.out.println(s1 == s2); System.out.println(s1.equals(s2)); 이렇게 비교하면 둘다 false가나온다 객체와 객체를 비교해서 그러므로문자열을 비교해야함. class Student{ String name; Student(String name){ this.name = name; } public boolean equals(Object obj) {Student s = obj; //불가능 return true ; }} class ObjectDemo { p..