File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Does java extend 2 classes at one time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Does java extend 2 classes at one time" Watch "Does java extend 2 classes at one time" New topic
Author

Does java extend 2 classes at one time

raghavan kanagiri
Greenhorn

Joined: Feb 07, 2014
Posts: 1
1) when you create a class and compile it and open and see the class using javap command .. that class file contains that it extends java.lang.object and a default constructor is created automatically..... But when you extends another class the java.lang.Object class is not appeared as extended why?

Code example:

1St Case ----- Java code:

public class temp(){

}

Javap Code:

public class temp() extends java.lang.Object {
public temp(){
}

}


2nd case --- Java Code:

public class temp() extends dummy{

}

javap Code:

public class temp() extends dummy{
public temp(){
}

}
why for the above scenario it doesn't extends object class .. if it does implicitly then why it did not do in the first case instead why did the compiler extends Object class ?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Welcome to CodeRanch!

A Java class can only have one direct superclass. In your example, Temp extends Dummy. Dummy extends Object. This means Temp indirectly extends Object. But the "extends" keyword only means the direct superclass.

Note that in Java, it is convention to begin class names with uppercase. This will make your code easier for others to read because it will be what they are expecting.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Scott Winterbourne
Ranch Hand

Joined: Jan 30, 2014
Posts: 115
    
    1

Welcome to the Ranch.

All classes in Java extend java.lang.Object by default.

As for why it shows a class extends Object when it doesn't extend anything else I'm not sure since every class extends Object by default.

When you extend your own class, that class still extends Object also. But it cannot extend more than one class other than Object.

[Edit] Jeanne beat me to the punch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
raghavan kanagiri wrote: . . . a default constructor is created automatically..... . . .
A default constructor is compiled iff you did not write any constructors yourself.

And welcome again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does java extend 2 classes at one time