File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about polymorphism. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about polymorphism." Watch "Question about polymorphism." New topic
Author

Question about polymorphism.

Amisha Shah
Ranch Hand

Joined: Mar 03, 2006
Posts: 33
what is an example of polymorphism ?

A. Inner class
B. Anonymous class
c. method overloding
D. method overriding.

I think ans should be B,D but ans is C. so please tell me what is correct ans.


Amisha Shah.<br />SCJP 1.4
Sandeep Singh Kunwar
Ranch Hand

Joined: Feb 27, 2006
Posts: 52
I think "method overloding" is all right, as:

# In computer science, polymorphism is the idea of allowing the same code to be used with different classes of data (which classes in typed languages correspond to types), resulting in more general and abstract implementations.
en.wikipedia.org/wiki/Polymorphism_(computer_science)

# In object-oriented programming theory, polymorphism is the ability of objects belonging to different types to respond to methods of the same name, each one according to the right type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, so this behavior can be implemented at run time (this is called late binding or dynamic binding).
en.wikipedia.org/wiki/Polymorphism_(object-oriented_programming)

The only confusion may be on overloading and overriding, i would like to hear more clarifications.


OfCourse Learner...<br />SCJP 5, SCWCD1.4<br />Blogs: <a href="http://sandeepkunwar.blogspot.com" target="_blank" rel="nofollow">http://sandeepkunwar.blogspot.com</a>
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
hi,
overlading?? noop because :

that's an overloading...it's not an example of polymorphism
Only anonymous class is a real exemple of polymorphism...because you reach the anonymous object throug a superclass reference.
Overiding is about inheritance...
i hope it help a bit
arno
[ April 17, 2006: Message edited by: Arno Reper ]

The man who makes no mistakes does not usually make anything<br /> <br />>>> SCJP 5.0 >> SCJD B&S <<< In progress
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
a tip: you shouldn't use wikipedia to study for SCJP, its not complete enough and it could create misunderstanding.
The best way for learning scjp is the ...well known and famous K&B books lol
arno
ps : i like wikipedia but not for studying a certification like scjp
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

I would go for B C and D. B because anon classes will subclass an existing class or implement an interface and C , D because inheritance is a form of polymorphism and both overloading and overriding can be considered as forms of polymorphism.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
are you sure? b,c,d?
i 'd go for the B only...
arno
ps : read k&b books pg 154
" Polymorphism applies to overriding not to overloading"...c is not ok
d maybe but...
[ April 17, 2006: Message edited by: Arno Reper ]
rikin shah
Greenhorn

Joined: Apr 17, 2006
Posts: 1
visit this link. It also has gr8 discussion of this que. I think both C & D. http://www.javaranch.com
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

You can google overloading and polymorphism.

Here is a wiki link.

http://en.wikipedia.org/wiki/Overloading
Leonardo Luiz
Ranch Hand

Joined: Mar 24, 2006
Posts: 51
Hi,

I think that must be "D. method overriding".

Polymorphism is provided by method overriding, when a method is invoked using a super class reference variable (or interface). So any different implementations, provided by sub classes, can be invoked like a unique method. It is closely related with inheritance.
Unlike, overloading is not dependent of inheritance and is not related with Polymorphism. It allows us to use the same method name with different arguments.

Sorry for my poor English.

Leonardo Luiz
Amisha Shah
Ranch Hand

Joined: Mar 03, 2006
Posts: 33
I think answers are B and D.

overrinding and anonymous claas. because polymorphysm is in play when anonymous classe are involved.
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
at least,i 'll say ( write ) its certainly not a and c ... b for sure, d its about inheritance...who polymorphism is about so maybe d also.
arno
swapnil paranjape
Ranch Hand

Joined: May 15, 2005
Posts: 126
hi

i have read this in one of the textbooks..

there are two types of polymorphism:

1)static polymorphism
2)dynamic or runtime polymorphism

overloading comes under staic polymorphism while overriding comes under runtime polymorphism...

polymorphism means having more than one form so overloading and overriding are part of polymorphism for sure...

please give your comments.
Changchun Wang
Ranch Hand

Joined: Feb 15, 2006
Posts: 83
from jsl4

polymorphism, meaning that an object of a given class can have multiple forms, either as its own class or as any class it extends. The new class is a subclass or extended class of the class it extends; the class that is extended is its superclass.


hence i think polymorphism effect on object other than methods or others
paresh mishra
Greenhorn

Joined: Apr 18, 2006
Posts: 1
there is 2 type of polymorphism
1: early binding
2: late binding
thease are achived through
method overloading , method overriding
Vijendra Runwal
Ranch Hand

Joined: Apr 17, 2006
Posts: 52
The answer is c & d.
method overloading and method overriding are the types of polymorphism.
Method Overloading is static polymorphism and Method Overriding is Dynamic Polymorphism.
Polymorphism is nothing but one thing existing in different forms.
That's what we do with method overloading i.e same function name with different types and/or number of arguments and in case of method overriding it's the same function name(present in both base as well as derived class) but execution depends on who(object of base class or derived class) called the function(object reference used).


SCJP 1.4,SCWCD
faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Originally posted by swapnil paranjape:

i have read this in one of the textbooks..

there are two types of polymorphism:

1)static polymorphism
2)dynamic or runtime polymorphism



hello swapnil ,

I agree with you polymorphism are of two types static(compile time) and dynamic (run time), function overloading is an example of static polymorphism , where as overriding functions of base class in a derived class is an example of runtime polymorphism.
[ April 18, 2006: Message edited by: faisal usmani ]
Swosti Dipan Pal
Ranch Hand

Joined: Sep 23, 2005
Posts: 70
Can anyone finally tell what is the correct answer ? It's bit confusing for me now.

Cheers,
-Biswa


Thanks<br />-Swosti
Deepak Santhosh
Greenhorn

Joined: Jul 20, 2012
Posts: 1

Both method overloading and overriding are examples of polymorphism
Pritish Chakraborty
Ranch Hand

Joined: Jun 12, 2012
Posts: 91

B) - because anonymous class overriden methods are invoked using superclass references
C) - compile time polymorphism
D) - runtime polymorphism

What's the issue??

In the end, maybe they won't accept B) for an answer. C) and D) are definitely answers though.


OCJP 6
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

Well in the orthodox way B, C and D are correct. Explanation similar to Pritish. But the main point here is what do you understand by "Polymorphism". What exactly is poly-morphed? The behavior of an object is poly-morphed which can happen if the compiler resolves it or its resolved at run time. I wouldn't say compile time resolution is a great example of polymorphism as the behaviour is bound and cannot change after that.


[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about polymorphism.
 
Similar Threads
Discuss the answer of a scjp concern run the program.
jsp /java i m not able to fine currect solutions
mock problem
the Quession about static of inner class
Thread1