• 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
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Interface

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the class in java extends from Object.
Similarly is there anything from which the interface extends from?
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello "Shaliey G"-

On your way in you may have missed that JavaRanch has a policy on display names, and yours does not comply with it - please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.

As to your question, interfaces do not have a common root - there is no specific functionality that all interfaces have to contain.
 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Interfaces also extends Object
 
bnkiran kumar
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i mean is
interface kumar;//assume
Kumar a=new Kiran();
Kiran is a class that implements interface kumar
then a instanceof Object is true....
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
As far as I know, interfaces dont have a common base.
thanks,
Vipin
 
Shaliey Gowtham
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forgive me if i am wrong but the naming policy suggests we can use initials
Please reply me, i will change the display name.
 
Vipin Das
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interface kumar;//assume
Kumar a=new Kiran();
Kiran is a class that implements interface kumar
then a instanceof Object is true....

It is true that the class Kiran is an instance of Object, but I think the interface kumar is not.


thanks,
Vipin
 
bnkiran kumar
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya vipin you are right as we cannot create objects of interface but at compile time it is checking na if there is subclass super class relationship exits or not.
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Forgive me if i am wrong but the naming policy suggests we can use initials


The display name should be first name, then a space, then the last name. Initials are OK for the first name only.
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interface doesnot extend any class.

Check out using javap JVM command.
 
Shaliey Gowtham
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies and also i have changed the display name
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Girish Nagaraj:
Interface doesnot extend any class.

Check out using javap JVM command.



I think javap is lying, but hiding some details is a nicer thing to say. If you use jclasslib bytecode viewer, you'll see that the interface does extend java.lang.Object.

First of, actually it doesn't matter because all classes extend from java.lang.Object anyway and you can't create an object from an interface.

However, this is way to much for the SCJP, so for completeness. I think it has to do with classes and JVM's verification algorithm that demands that all classes (and an interface is just a special class) except java.lang.Object itself have a superclass.
 
bnkiran kumar
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are right Dick.
 
Shaliey Gowtham
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how can an interface extend a Class
 
Dick Eimers
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shaliey Gowtham:
But how can an interface extend a Class



As far as the Java programming language is concerned, that cannot be done.

So, if you encounter a question on the SCJP exam along the lines of 'interface Foo extends Bar', then you know that this is illegal/bogus. However, when looking at the Foo.class file generated by 'interface Foo { }' with some bytecode viewer you'll notice that it does extends java.lang.Object for reasons stated in my previous post, but as a (to become) SCJP you shouldn't care.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for delayed entry ..


First of, actually it doesn't matter because all classes extend from java.lang.Object anyway and you can't create an object from an interface.



we can create an object with interface like

Runnable r=new Runnable(){ public void run(){} };

Then wht is the super class for this ??
I think it is the object.
 
bnkiran kumar
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you said is right you are actually declaring anonymous class which implements Runnable interface and extends Object class and at the same time you are creating object of the that class.

any class extend from Object class,
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes all anonymous interface instantiations are really subclasses of Object
that implement the named interface. As such they possess all the methods
of Object and you can override those in your implementation as well as the ones spelled out in the interface declaration.
 
Girish Nagaraj
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dick Eimers,

Have a look at this code...

interface Interface {}

abstract class Abstract {}

now when I gave 'javap -c Interface' this is what I got.

Compiled from "Scjp26.java"
interface Interface{
}

and for 'javap -c Abstract' this is what I got.

Compiled from "Scjp26.java"
abstract class Abstract extends java.lang.Object{
Abstract();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>" )V
4: return

}

Still do you think interface's extend java.lang.Object???
 
Dick Eimers
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Girish Nagaraj:
Hi Dick Eimers,

Have a look at this code...

interface Interface {}

abstract class Abstract {}

now when I gave 'javap -c Interface' this is what I got.

Compiled from "Scjp26.java"
interface Interface{
}

and for 'javap -c Abstract' this is what I got.

Compiled from "Scjp26.java"
abstract class Abstract extends java.lang.Object{
Abstract();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>" )V
4: return

}

Still do you think interface's extend java.lang.Object???



Yes. Like I said, javap is lying to us. Download the class viewer I mentioned in a previous post and see for yourself.
 
bnkiran kumar
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Girish Nagaraj
can you explain what is this javap command do
 
Dick Eimers
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by bnkiran kumar:
[..] can you explain what is this javap command do



The Java virtual machine has no notion of the Java programming language and
instead processes files in a particular binary format, called the Java Class File format. A class file mainly consists of Java virtual machine instructions (a.k.a. Java bytecodes) and a symbol table, called constant pool, as well as ancillary information. Never mind.

javac, the best-known Java compiler provided by Sun, compiles Java source files to .class files and javap is a tool used to dump out various types of information about .class files.

Just type 'javap -help' to view its options..
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ...
i think the interface (which its name implies) is just an interface... and does not extends from Object...
BUT... any implementer of that interface may extends that Object..
do you agree with me?
bye
[ April 28, 2006: Message edited by: ali tareq ]
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic