Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
SCJP 6 [SCJP - Old is Gold]
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 6 [SCJP - Old is Gold]
Dieter Quickfend wrote:I'm confused. In an exam I took, I think it was the ExamLab diagnostic, there was a question that said "An Interface IS-A Object", and my answer was false because obviously, an interface cannot inherit from a class. My answer was wrong, and the explanation said an Interface really IS-A Object, because any interface reference can be assigned to an Object.
Regards,
Avishkar Nikale
I also followed ExamLab... Explanation was clear... Explanation is like Interface "IS-A" Object... You can see double quoted "IS-A"... That is "Interface" type reference variable referring to class implementing it, can be directly assigned to "Object" type references variable since classes implementing interfaces is a sub-class Of Object... So no need of explicit typecasting...
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Regards,
Avishkar Nikale
Dieter Quickfend wrote:Is it a loophole so everything would be an Object, and interfaces don't really extend Objects
Joanne
Regards,
Avishkar Nikale
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Avishkar Nikale wrote:I suspect that the compiler allows the same because it knows that at runtime the reference
will finally be pointing to an Object or its subtype.
Joanne
Regards,
Avishkar Nikale
Matthew Brown wrote:I'd be happier with something like: "If T is an interface, then a T IS-A Object", because that way it makes it clear that the IS-A relationship is referring to instances of T.
David Newton wrote:
Matthew Brown wrote:I'd be happier with something like: "If T is an interface, then a T IS-A Object", because that way it makes it clear that the IS-A relationship is referring to instances of T.
But your wording is just as unclear. If T is an *implementation* of an interface [...] removes the ambiguity.
Author of ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- OCPJP Online Training -- Twitter -- How to Ask a Question
David Newton wrote:It could mean that T is an interface.T isn't an object, it's an interface. An instance of an implementation of T is an object.
[My Page] | [JavaRanch FAQ] | SCJP6
"I am not afraid of the storm, as I am learning to sail my ship"
Regards,
Avishkar Nikale
Sriram Gsn wrote:An Interface has no state
Avishkar Nikale wrote:Can the moderators end this topic as resolved with proper resolution provided in the last post ?
Sriram Gsn wrote:Maybe the ExamLab question was referring to.. "An Interface reference IS-A Object", which surely is, since it refers to the instance of the class which implements the interface in question.
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Mike Simmons wrote:
Sriram Gsn wrote:An Interface has no state
Not quite true. (...) I leave this (for now) as a challenge for readers: when does an interface have state? No, I'm not talking about state in a class that implements the interface. I'm talking about state in the interface itself.
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Matthew Brown wrote:I'd argue that the usual convension would be that "a <classname>" == "an instance of <classname>", and "a <interface>" == "an instance of an implementation of <interface>".
Matthew Brown wrote:It's probably not worth worrying about, though.
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Anand Hariharan wrote:
Mike Simmons wrote:
Sriram Gsn wrote:An Interface has no state
Not quite true. (...) I leave this (for now) as a challenge for readers: when does an interface have state? No, I'm not talking about state in a class that implements the interface. I'm talking about state in the interface itself.
I'll bite. So when does an interface have a state? I expect your explanation will hold water to your statement "not talking about state in a class that implements the interface, [but] in the interface itself".
Mike Simmons wrote:The issue is with fields in interfaces. Such fields are implicitly public, static, and final, and they must be initialized where they are declared.
Mike Simmons wrote:So they are much like constants, and we tend to think of them that way. But there is no requirement that the field needs to refer to an immutable object. For primitive fields, this isn't a problem. A final primitive is immutable and therefore stateless, no problem. But a final reference variable can easily refer to a mutable object that does have state.
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Anand Hariharan wrote:I consider this to be a defect (or at best a very annoying quirk) of Java.
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Dieter Quickfend wrote:Correct me if I'm wrong, but, I am led to believe that, in Java, only instance members can be part of an object's state.
Dieter Quickfend wrote:An interface can have a constant that, in its turn, has state, but it doesn't have state of itself.
Dieter Quickfend wrote:... As any field in an interface is implicitly static, it is acceptable to understand that in Java, an interface cannot have state...
Dieter Quickfend wrote:... An interface can have a constant that, in its turn, has state, but it doesn't have state of itself.
OCPJP 6
Dieter Quickfend wrote:any interface reference can be assigned to an Object.
SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar wrote:but we cannot say that interface "ISA" Object
David Newton wrote:
Shanky Sohar wrote:but we cannot say that interface "ISA" Object
Depends on how you're using it. Canonical usage of the term "is-a" *does* let you say "(instance of class that implements Foo) is-a Foo", since that's the point of interfaces.
SCJP6.0,My blog Ranchers from Delhi
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|