presentation30 - public static void main(String[] args){...

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

View Full Document Right Arrow Icon
Refection Soheil Hassas Yeganeh Computer Engineering Department ShariF University oF Technology
Background image of page 1

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

View Full DocumentRight Arrow Icon
A Problem 2
Background image of page 2
A Problem We have an unknown set of List implementations . We can use any of them in our program. But, we want the user to specify his/her wanted implementation. 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
What we need ? (1) 3 Method Class Name Class
Background image of page 4
What we need ? (1) 1. A mechanism to load the class using a string . I want to load a class named “java.util.ArrayList”. 3 Method Class Name Class
Background image of page 5

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

View Full DocumentRight Arrow Icon
What we need ? (2) 4 Method Class Object
Background image of page 6
What we need ? (2) 1. A mechanism to instantiate a class at runtime. I want to instantiate a Class object java.util.ArrayList . 4 Method Class Object
Background image of page 7

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

View Full DocumentRight Arrow Icon
java.lang.Class 5 Test.java class Test { public static void main(String[] args){ Class klass = Test.class; System.out. println(klass); } }
Background image of page 8
java.lang.Class Class is the class for classes in Java! If you want to access the Class object of a class , you can use .class Feld. What are the methods of the Class? 5 Test.java class Test {
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

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

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

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

View Full DocumentRight Arrow Icon
Background image of page 16
Background image of page 17

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

View Full DocumentRight Arrow Icon
Background image of page 18
Background image of page 19

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

View Full DocumentRight Arrow Icon
Background image of page 20
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public static void main(String[] args){ Class klass = Test.class; System.out. println(klass); } } Class Methods 6 Class Methods • Class should have methods that allow us to access its • Fields , Methods , Super Class , Interfaces , Package , Visibility , . .. • Class.forName() gets a string and loads a class. • Let’s see a sample! 6 Other Classes 7 Other Classes • java.lang.refect. Constructor • java.lang.refect. Field • java.lang.refect. Method • java.lang.refect. Package • .... 7 Class of Object 8 Class of Object • Object’s getClass() method! 8 Accessibility 9 Accessibility • A feld, a constructor, or a method, can be private , and we do not have access to it . • Using reFection we can make it accessible . • Let’s see a sample! 9 The Problem 10 The Problem • Let’s write a program to solve our problem. 10 Any Questions?...
View Full Document

This note was uploaded on 11/21/2010 for the course COMPUTER S 003 taught by Professor Izadi during the Spring '10 term at Amirkabir University of Technology.

Page1 / 20

presentation30 - public static void main(String[] args){...

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

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