Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

overriding.

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if we got this example:
class A{
private void a(){}
}
abstract class B extends A{
abstract protected void a();
}
class C extends B{
public void a(){}
}
does method a in class C overrides method a in class A ?
thank you!
ciao!

------------------
edi kapllani
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the method in C doed not override the method in A. Actually since the method in A is declared as privete, neither classes B or C is even aware of it.

Bosun
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
edi,
Please change your name to be compliant with JavaRanch's naming policy.
Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
Thanks,
Cindy
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public abstract class A{
public void a();
}
class B extends A{

public void a(){
//anykind of method
}
}

can method a in abstrct class A overrides method a in class B in this case?
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,
Whenever you have a abstract method in a class you have to declare it as abstract. So your class A defition look like this,

public abstract class A{
public abstract void a();
}

In that case the 'a' method is overriden in class B.

-Manju
[ September 06, 2004: Message edited by: Manjunath Subramanian ]
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMHO, Tim doesn't have to declare method a() in abstract class A as abstract.

You can't have a concrete class containing an abstract method, but you can have an abstract class containing a concrete method.
[ September 06, 2004: Message edited by: Mike Gershman ]
 
Tim Leung
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear mike.

As you said, all method in abstract class and its subclass (may be a class or abstract class) must contains override method.is it correct?

abstract class A{
abstract void methodA();
}

class B extends A{
void methodA(){
}
}

since methodA in class B must be used. How about interface?

interface A{
void methodA();
}

class B implements A{
void methodA(){
}
}
Is it also override?
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your examples of overriding methods are both correct. In each case, class B needed an implementation of MethodA.

However, let me modify your first example:



class B does not require its own implementation of MethodB because it inherits a concrete implementation of methodB from class A.

BTW, try using the code tags, they preserve the indentation of your examples for readability.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,

Manju's example is 100% correct as -


b'coz Tim havn't given the body tag's to method a().

Although you are also correct as -


You can't have a concrete class containing an abstract method, but you can have an abstract class containing a concrete method.



-Abhi.
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic