aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help-SCJP-65 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help-SCJP-65" Watch "help-SCJP-65" New topic
Author

help-SCJP-65

dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Hi !

Please anyone guide me regarding the exam.

There are two books---Kathy Seirra
Kathy & berty

Which book to refer for certification ?

Thank You.
Marco Piva
Greenhorn

Joined: Aug 24, 2007
Posts: 12
http://faq.javaranch.com/java/ScjpFaq#books


SCJP 5.0
Bilal A. Siddiqui
Ranch Hand

Joined: Sep 14, 2008
Posts: 53

use kathy sierra & bert bates


Cheers!!! Bilal
Handsome Android||@bilal_speed||LinkedIn
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
HI,

I am not able to get this code: Chapter 2 K&B exercise problem 13
class Mammal
{
String name = "Hello";

String make()
{
return "A";
}
}


class zef extends Mammal
{
String name = "HHH";

String make()
{
return "S";
}
}

public class Zoo
{
public static void main(String args[])
{
new Zoo().go();
}

void go()
{
Mammal m = new zef();

System.out.println(m.name+m.make());
}
}


Output: HelloS

I know m is an object of class zef referencing to class Mammal.

So m.name will display the instance variable of class Mammal.

But what about the method make ?
Why the instance method looks the subclass.

Can anyone explain this ?

Thank you.
Dimple.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
because the reference variable m is referring to subclass object so overridden method will be called.


SCJP 1.6 96%
Rajiv Chopra
Ranch Hand

Joined: Dec 19, 2008
Posts: 62
Neha Daga wrote:because the reference variable m is referring to subclass object so overridden method will be called.



This is called Polymorphism.


Rajeev Kumar
SCJP 6.0 Certified 96%
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Neha Daga wrote:because the reference variable m is referring to subclass object so overridden method will be called.


that means when an reference variable is referring to any other class it will invoked the method of the class it belongs.

In other words in this case

Mammal m = new zef();

if make() is a method in both class Mammal and zef

When i say m.make the make method of subclass will be called.

It also means that m.name calls the variable of reference class Mammal

and m.make() calls the method to which it belongs no matter to whom the object m is referring to.
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Rajiv Chopra wrote:
Neha Daga wrote:because the reference variable m is referring to subclass object so overridden method will be called.



This is called Polymorphism.


i know this is mentioned in the book that

Polymorphism is only with the instance methods.

Topics are not cleared unless practically some code is wriiten and seen how it works.

Thank you.
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
so dear you have the solution....code code code....


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Raju Champaklal wrote:so dear you have the solution....code code code....



I am done with the chapters of K&B i.e 1,2,3,4,5,7 except 6,7,8,9 which i kept at hault fot sometime.

I thought let make first few chapter thro with it proper uderstanding of the class.

Thank you for clearing the doubts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help-SCJP-65