• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Object and Abstract, Non- Abstract Classes & Methods

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I need help in understanding the two concepts.
The first is on the difference between abstract and non-abstract classes and methods. Please do help in understanding the concept with a simple example.

The second would be on a basic one. What would happen if the object instantiated is to a new class. For eg say "Object1 a = new Object2();". In this case, to which obect would a point to ?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kalyan Naveenan wrote:
The first is on the difference between abstract and non-abstract classes and methods. Please do help in understanding the concept with a simple example.



Abstract class - specification + default implementation.
Non-abstract class - implementation(override common implementation if necessary)

typically, NonAbstractClass extends AbstractClass; for instance, ArrayList extends AbstractList (from Java API)

Kalyan Naveenan wrote:
The second would be on a basic one. What would happen if the object instantiated is to a new class. For eg say "Object1 a = new Object2();". In this case, to which obect would a point to ?


Object1 a = new Object2(); you can't do this unless Object1 and Object2 has relationship; more over Object1 must be a super type of Object2
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And abstract method can't have implementation. i.e, no method body . it means subclass must handle that method !
 
Kalyan Naveenan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kalyan Naveenan wrote:The second would be on a basic one. What would happen if the object instantiated is to a new class. For eg say "Object1 a = new Object2();". In this case, to which obect would a point to ?

Object1 a = new Object2(); you can't do this unless Object1 and Object2 has relationship; more over Object1 must be a super type of Object2



Ok, in this case let me say, i have a Y class inherited from a X class. So how would Y my = new X(); instantiate?
 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kalyan Naveenan wrote:i have a Y class inherited from a X class. So how would Y my = new X(); instantiate?





Hope this helps you!
 
Kalyan Naveenan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arjun Srivastava wrote:

Kalyan Naveenan wrote:i have a Y class inherited from a X class. So how would Y my = new X(); instantiate?





Hope this helps you!



No, I would like to know on the actions based on heap memory. As in, for the instance new Y(), would it be treated as a child object to that of the X? Or fundamentally what would happen ?
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kalyan Naveenan wrote:
No, I would like to know on the actions based on heap memory. As in, for the instance new Y(), would it be treated as a child object to that of the X? Or fundamentally what would happen ?


I am not sure about your question.
But still Fundamentally,If you say

Parent class reference variable p would be pointing to an object of Child class in the Heap Memory.
 
Kalyan Naveenan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arjun Srivastava wrote:

Parent class reference variable p would be pointing to an object of Child class in the Heap Memory.



Exactly whaat i waned. thanks a ton.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic