• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Super class for all the classes in java

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which is the super class for java Language...
this is an interview question .
I SAY Object is the super class for java Language ...

then he asked whether object class will extend ??

i say Yes it will implectly extend ...
then he whether each and every class will extend object
i say yes ...
then he asked multiple inheritance is possible in java ...
i say no ...

then how will say object class will extend in each and every class....
hai friends if there is any solution tell mem

by
dhana
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
When you create a subclass like,
class child extends parent this means child is not the direct subclass of class Object, "child" is the sub class of "parent" and "parent" is a subclass of "Object" .. So this means that child is also an "Object" and it doesn't means that it's multiple inheritance it's only single inheritance.

If you are C++ programmer you can say
class child : public parent1,public parent2 ( i'm sorry if the above C++ syntax is wrong ). This piece of code says that child has all the non private members of parent1 & parent2 directly inherited this is multiple inheritance.


PS: Please check your display name before a bartender catches you!!
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi the Signature of Object Class is
public class java.lang.Object then what do you mean by these lines ?

then he asked whether object class will extend ??
i say Yes it will implectly extend ...

 
dhana sss
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai friends ,,
am asking .. there is one class

class test
{
public static void main(String arg[])
{
System.out.println("whether this class will extends public class java.lang.Object");
}
}
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Obviously it has to.
Execute this piece of code.



You can see true in the console.
[ March 21, 2005: Message edited by: Srinivasa Raghavan ]
 
dhana sss
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then u'r saying that all the classes will extend Object Class ...
am i right ...
tell me "srini"

by
dhana
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All classes extend Object in one of three ways:

1.
class A extends Object {...} // Object is the direct superclass

2.
class A {...} // Object is still the direct superclass

3.
class X {...}
class A extends X {...} // Object is an indirect superclass

Every class's constructors chain up to eventually call the Object no-arg constructor and every class inherits Object's methods like equals(), finalize(), and hashcode().
 
dhana sss
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there any difference between implicit and explicit class
if any tell me ...

by
dhana
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What do you mean by "implicit and explicit class" ?
 
dhana sss
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i do no u only say A class extend Explicitly and object class will extend Implicitly .....
by
dhana
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The master of all classes in java plus the one you create every day.
Java does support multiple inheritance, right. But how ? that is through
implimentation of interfaces. Unlike c++, you can't do the following in java.

class Sub extends Super,Object{};

But implicitely, every class created in java extends Object.
that why you inherit some methods like wait(), toString ....
from class Object. eg

class Tricky{} // implicitly = the compiler sees class Tricky extends Object

class BeNice extends Tricky {}
// what you have is what you typed, there isn't a direct call to Object
// by BeNice class but it extends Object through inheritance.

Wao , hope it helps
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All classes directly or indirectly inherit from java.lang.Object, with one exception.
All classes have one, and only one, superclass, with one exception.
The exception is both cases is for java.lang.Object itself.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic