Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance

 
Mary Robert
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! friends,
This is a question rom a mock exam..
Which of the following are true about interfaces. Select all correct answers.
a)Methods declared in interfaces are implicitly private.
b)Variables declared in interfaces are implicitly public, static, and final.
c)An interface can extend any number of interfaces.
d)The keyword implements indicate that an interface inherits from another.
I thought the answer would be only 'b'. But it is given that the answer is b & c. How is this?
As of my knowledge, u can extend atmost one class and implement multiple interfaces. Is it not true with the interfaces too?
Please help me..
Thank u
Mary.
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answers b and c are correct. An interface can extend several interfaces, unlike classes.
 
Tom Pridham
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer C is not worded correctly. An interface can only extend one interface, not multiples (same as classes).
I see why it is confusing. Answer C should be re-worded to say something like "c) An interface can extend another interface." or something like that.
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is straight from Khalid pg. 197 and I quote "An interface can extend other interfaces, using the extends clause. Unlike extending classes, an interface can extend several interfaces." So Todd I believe your wrong and my original answer is correct. Interfaces can extend multiple interfaces unlike classes. Correct me if I'm wrong.
 
Tom Pridham
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ignore my last post.....Interfaces can extend multiple interfaces like:
public interface a
{
}
interface b
{
}
interface c extends a, b
{
}
This code is legal and compiles correctly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic