aspose file tools*
The moose likes Beginning Java and the fly likes Object Hierarchy in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object Hierarchy in Java" Watch "Object Hierarchy in Java" New topic
Author

Object Hierarchy in Java

Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Hi All,

Can you please let me know, what does Object Hierarchy means in Java?

Also please explain the role of Abstract Class and Interface in Hierarchy.

Thanks,
Sumeet


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3837

what does Object Hierarchy means in Java


Did you mean the Java API ?

Also please explain the role of Abstract Class and Interface in Hierarchy.


Abstract class is a class with abstract method(s) (i.e: methods with no body, just the method signature). Interfaces are 100% abstract that they can only contain abstract methods where as abstract classes may have non-abstract method(s) (i.e: methods with body). InterfaceVsAbstractClass compares them well.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3645
    
  15
Vijitha Kumara wrote:Abstract class is a class with abstract method(s)


Not necessarily. You can have an abstract class with no abstract methods.
An abstract class is a class that cannot be instantiated, only extended.


Joanne
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3837

Joanne Neal wrote:Not necessarily. You can have an abstract class with no abstract methods.


Of course, just miss that when writing
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Sut Pat wrote:Hi All,

Can you please let me know, what does Object Hierarchy means in Java?



If i am not wrong then Packages and Access Specifiers may help you.


http://muhammadkhojaye.blogspot.com/
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

These are fundamental Java issues, so I'm moving this to the beginner's forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
To me, a fundamental aspect of the heirarchy in Java is organization, a way of organizing the functionality of Java into "layers" so that each successive layer adds functionality to the heirarchy. Anyways, that's not the whole picture, just one way of looking at it.

Each API document for a class begins with a little chart, such as the following for JFrame class



the purpose of the little chart is to show the position of the class within the Class heirarchy. Each class in the heirarchy that leads to JFrame adds something to the functionality of JFrame. If you compare this with the heirarchy for JButton.



you can see that any functionality that JFrame and JButton have in common probably comes from the first three levels of the heirarchy, which are the same for both JButton and JFrame.

Anyways, that's not the whole picture, but it is a key part of it.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39386
    
  28
Somebody else was asking about concrete and abstract classes here. I don't know whether that will help you, but have a look.
Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Hi All,

Thanks for the input.

Can you please tell, "Interface takes part in Java Object Hierarchy" ?

Thanks.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Sut Pat wrote:Hi All,

Thanks for the input.

Can you please tell, "Interface takes part in Java Object Hierarchy" ?

Thanks.


No, not really.

Here is a quote from the Sun Java Tutorial

Interfaces have another very important role in the Java programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes. The Java programming language does not permit multiple inheritance (inheritance is discussed later in this lesson), but interfaces provide an alternative.

Hopefully you will find the following link useful.

http://java.sun.com/docs/books/tutorial/java/concepts/index.html

Peter Granstrom
Greenhorn

Joined: Jun 08, 2009
Posts: 10
To me object.hierarchy is what it sounds like, its the
hierarchy of Object, which mean everything that is
inherited from Object.. kinda like the description above..
if someone interfaces take part in the object hierarchy i would
say ye but only if its something you write that it should,. its not
something that is automatically inherited

Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

Fred Hamilton wrote:
Sut Pat wrote:Hi All,


Interfaces have another very important role in the Java programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes. The Java programming language does not permit multiple inheritance (inheritance is discussed later in this lesson), but interfaces provide an alternative.




so that means interfaces do not take part into object hierarchy but abstract classes do.and the compiler on seeing the implements keyword understands that an interface is used.
Please correct me if wrong.
Peter Granstrom
Greenhorn

Joined: Jun 08, 2009
Posts: 10
I think i read somewhere that all classes is related
to Class object so if you make an abstract class,.
it should be related to object only further up the
inheritance three..
but im not sure if this answer is everythin correct,
so i suggest you read further on this subject
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Sumit Patil wrote:
Fred Hamilton wrote:


Interfaces have another very important role in the Java programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes. The Java programming language does not permit multiple inheritance (inheritance is discussed later in this lesson), but interfaces provide an alternative.




so that means interfaces do not take part into object hierarchy but abstract classes do.and the compiler on seeing the implements keyword understands that an interface is used.
Please correct me if wrong.


That makes sense to me, Sumit. I'm not sure how you will take advantage of that information in a practical sense, but it is always good to understand these things.

It may help you to consider an interface in the same way you consider an Application Programming Interface. Classes inherit functionality from other classes that are higher in the heirarchy, Interfaces are not really about inheriting functionality, rather they enforce a set of rules about how a class that implements the interface should be designed.

Abstract classes never become objects, but they function in the heirarchy in the sense that non-abstract classes which will become objects can inherit functionality from abstract classes.

The following discussion of heirarchy with Swing components and containers was quite helpful to me.

http://java.sun.com/docs/books/tutorial/uiswing/components/index.html
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Peter Granstrom wrote:To me object.hierarchy is what it sounds like, its the
hierarchy of Object, which mean everything that is
inherited from Object.. kinda like the description above..
if someone interfaces take part in the object hierarchy i would
say ye but only if its something you write that it should,. its not
something that is automatically inherited



That is a good way of looking at it, but since we are talking semantics here, lets make the following clarification about class heirarchy vs object heirarchy.

Really, we are not saying that the heirarchy is made up of objects, we are saying it is made up of classes of Which Object is the uppermost class. In that sense it makes a difference when we say Object as opposed to object. cause they mean two different things. Capitalization of the first letter matters here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object Hierarchy in Java