Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extend class

 
Jello Yao
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a subclass extend more than one class during declaration? i.e. class Sheep extends Cattle, Animal. Thanks!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it can only extend one class and implement as many interfaces as you want.
 
Divya Venkatesh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No,
Java does not allow multiple inheritance.You may extend Just one class and implement as many interfaces as you need just providing functions for the abstract methods.
Hope this helps.
 
bhatti mansha
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no , java can not aloud to make multiple superclasses
but a superclass have a lot of sub classes
means eg
class a{
}
class b extends a{
}
class c extends a{
}
in it "a" is a super class and "b" is sub class who extend him but "c" also extends "a" so "a" is also superclass of "C".
it is possible;
but a subclass can not create a multiple
superclasses
eg
class a{
}
class b extends a{
}
class c extends a,b {// error
}
but interface u can extends more then 2 interface
e.g
interface a {
}
interface b{
}
class C implement a,b{
}
it is possible
ok i hope u r clear more
if i can write some wrong plz clear me
thanx
Faheem
 
Robbie shi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in java one class can only have a direct
superclass
--
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
though different, its also good learning if you explore classes in relation to interfaces. A class could implement many of them e.g. class TClass implements Interface1, Interface2{....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic