• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is Interface a datatype?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question from JavaCaps Mock Exam.
19. Select all correct answers about what is the definition of an interface?
A) It is a blue print
B) A new data type
C) Nothing but a class definition
D) To provide multiple inheritance
The given answers are:
A,B & D.
My question is can an Interface be considered as a datatype?
Thanks
Diaz
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's considered as a supertype actually.
Variables of an interface type can be declared. If a class implements an interface, then references to objects of this class and its subclasses can be assigned to a variable of this interface type.
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would agree that class is a new data type in OOD. An interface has everything a class has except it does not have actual body of methods. It has definition of new data type, method names, variable names, method signature and return type. For all practical purposes Interface is a new data type.
 
Diaz Thomas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My doubt was this. We can't instantiate an interface. An interface has to be implemented by a class for anyone to use it. Then it becomes a property of the class. All the variables in the interface can be referred using an instance of the class. Then the class can be considered as a datatype. I know it is possible to make references to the variables in an interface from a class which implements the interface by using the interfaceName.variableName.
Now I don't know what is the definition of a datatype!!!
Please help guys..
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An interface represents a type. For more on types, see this link.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is yes,

My explanation may be lenghty.
Lets consider an interface "Actor",
and a Concrete Class "StageActor" which implements Actor.
in that case the following statement is valid
Actor a = new StageActor();
here we are creating an instance of SubClass and refer is as a super class datatype (principle of inheritance)
and if you notice we have used the interface Actor as a datatype.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More on what Prakash wrote: now the refererence a is of a (declared/compile) type Actor different from StageActor. It will be accessed only for the members declared in Actor. It isn't possible to call on it the methods defined exclusively in StageActor.
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a very poorly worded mock question. I don't think you'll see anything like it on the real exam.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I always thought that aim of most folks at forum was not only to obtain certification but also to learn the language. Please dont stop any discussion by saying "I don't think you'll see anything like it on the real exam". It might not come in the exam but it is not a waste of time for those people asking it and answering it.
Dont mean no offence.
Thanks
Bishal
 
Diaz Thomas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys. I've a better understanding now.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't want to stop discussion. I just think that the question is so badly written that trying to figure out what it really means isn't especially productive.
Java does not have multiple inheritance. A class can implement as many interfaces as it wants, but it still inherits from (extends) only one superclass.
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic