Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JavaRanch #19

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question asks: "TRUE or FALSE: methods which are marked protected can be called on any subclass of the class in which the method is declared." The answer is given as TRUE.
What does "called on any subclass" mean? That answer is certainly true if "on" means "in".
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I read "called on any subclass" I imagine we're talking about taking an instance of the subclass and using it to invoke the method, as in subclassInstance.protectedMethod(). This would make the statement FALSE since you can't do that from within an unrelated class. I think you're right that the question was meant to say "in" rather than "on".
 
Trailboss
Posts: 23446
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The change is made.
(I'm sure glad I numbered the questions!)
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still think is it FALSE (so
class A
{
protected void printName()
{
System.out.println("A");
}
}
class B extends A
{
protected void printName()
{
System.out.println("B");
}
}
class C extends B
{
protected void printName()
{
System.out.println("C");
}

static void main(String argc[])
{
//HOW DO I CALL A's printName, I don't
}
}
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
you can call A's method by making object of A like
A ob1=new A();
ob1.printName();
which give output "A"

Amit
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic