You are on page 1of 2

Page 1 of 2

Lecture ID: IT404/2015/March/01

IT-2A

1. Write a Java class with a method which accepts parameters belonging to any
type.
The method should:
a)
b)
c)
d)

Print the sum of the numbers passed as its parameters


Print the number of characters in each String argument
Print ASCII value of any character that may be passed.
Display the elements of an array that may be passed to it

Think:
i)

The signature of the method?

ii)

Return type

iii)

Parameter types? *** Need to think over it.

iv)

Hint-1: Base class reference can hold object of Child class

v)

Still not clear!

vi)

Hint-2: You need a class which is Base to all classes (types).

vii)

I'm sure, you can now understand.

viii)
ix)

Well, it's the Universal forefather viz. Super class


Guessed it right! I talk about universal super class i.e.

java.lang.Object
x)
xi)

Now do it. Iterate over the array of parameters


How would you know the type of a parameter or variable

soham.jisit@gmail.com

+91-9830-740-684

http://sohamsironline.weebly.com

Page 2 of 2

Lecture ID: IT404/2015/March/01

IT-2A

You learned:
Why to use Object array
Object can be substitute or Proxy to any type
Java 1.5 onwards primitive types automatically
become object of respective Wrapper classes
o Boolean Boolean
o Integer int
o Double double
o Character char

etc.

How to check type of an object using

[B] Think Again!


i) Did this meet my requirement?
i. Suman: To certain extent means: Not fully
ii) Where does it lack?
[C] I wanted something like this:

No need to do too much research and put efforts aimlessly on it.


Just make the following change in your existing code
Just use Object instead of Object[] and keep the rest same
This stands for variable number of arguments to a method

soham.jisit@gmail.com

+91-9830-740-684

http://sohamsironline.weebly.com

You might also like