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

Object Hierarchy in Java

 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are fundamental Java issues, so I'm moving this to the beginner's forum.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48452
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thanks for the input.

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

Thanks.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic