java oop 22 Object 클래스

bitcogo·2022년 4월 16일
0

Object 클래스
- 모든 클래스의 최고 조상
- 부모가 없는 클래스는 자동적으로 Object 클래스를 상속받게 된다.
- 모든 클래스는 Object클래스에 정의된 11개의 메서드를 상속받는다
toString(),equals(),hashCode()...
public class Oop22_objectClass {

   public static void main(String[] args) {
      
        Practice pp = new Practice();

        //Practice클래스 안에 toString 없지만 Object클래스의 상속받으니까 쓸 수 있다
        System.out.println(pp.toString());//Practice@28a418fc 객체의주소
        //객체를 println()에 넣으면 객체의주소를 반환해준다.
        System.out.println(pp);//Practice@28a418fc 객체의주소
    }
}
//부모클래스가 없으면 컴파일러가
//자동으로 Object클래스 상속받게 해줌
	class Practice extends Object{
   		 int a;
   }		
profile
공부하고 기록하는 블로그

0개의 댓글