presentation19 - java.lang.Object Soheil Hassas Yeganeh...

Info iconThis preview shows pages 1–18. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: java.lang.Object Soheil Hassas Yeganeh Computer Engineering Department Sharif University of Technology java.lang.Object 2 java.lang.Object • Object is the root of the type tree in java. • Object is a super class of every class . 2 1 st Example 3 Shape.java class Shape { } Shape.java class Shape extends Object{ } 1 st Example • No difference between these alternatives. • Java adds extends Object for every class, implicitly . 3 Shape.java class Shape { } Shape.java class Shape extends Object{ } 2 nd Example 4 Shape.java class Shape { public static void main(String[] args){ Object obj = new Shape(); } } 2 nd Example • It is OK! • Object is a super class of Shape. 4 Shape.java class Shape { public static void main(String[] args){ Object obj = new Shape(); } } Is Object the supper class of Shape[]? Arrays and Hierarchy (1) 6 Arrays and Hierarchy (1) • Array is also a type . • Any type in Java is a child of Object. • So any instance of Shape[] is also an Object . 6 3 rd Example 7 Shape.java class Shape { public static void main(String[] args){ Shape[] sh = new Shape[2]; Object obj = sh; Shape[][] twoDimArr = new Shape[2][2]; Object obj2 = twoDimArr; } } 3 rd Example • Any array is also an object. 7 Shape.java class Shape { public static void main(String[] args){ Shape[] sh = new Shape[2]; Object obj = sh; Shape[][] twoDimArr = new Shape[2][2]; Object obj2 = twoDimArr; } } 4 th Example 8 Shape[] Shape[][] Shape[][][] Shape[] Circle[] Point[] 4 th Example • None of them is valid. • Any array is a direct child of Object . 8 Shape[] Shape[][] Shape[][][] Shape[] Circle[] Point[] Object Equality 9 A B Object Equality • Which of the following statements are true? • A is A. • B is B. • A is B. • B is A. • Which of the following statements are true? • A is the same as A. • B is the same as B....
View Full Document

{[ snackBarMessage ]}

Page1 / 43

presentation19 - java.lang.Object Soheil Hassas Yeganeh...

This preview shows document pages 1 - 18. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online