• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

help-SCJP-65

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !

Please anyone guide me regarding the exam.

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

Which book to refer for certification ?

Thank You.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/ScjpFaq#books
 
Ranch Hand
Posts: 53
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use kathy sierra & bert bates
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because the reference variable m is referring to subclass object so overridden method will be called.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neha Daga wrote:because the reference variable m is referring to subclass object so overridden method will be called.




This is called Polymorphism.
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so dear you have the solution....code code code....
 
dimple bav
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Yeah, but is it art? What do you think tiny ad?
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic