Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Classes and interfaces

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Public XXXX extends something1, something2

1.- XXX should be an interface,something1 and something2 need not, for the expression to be legal
2.- XXX should be a class, something1 and something2 must be interfaces for the expression to be legal.
3.- XXX, something1 and something2 must be interfaces for the expression to be legal.
The above statement is alway illegal in Java as multiple inheritance is not supported.
The correct answer is 3 but why is not 2??? I think that I see a lot of times a Class with 2 interfaces!
Thakns in advance.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
Look at option 2. If it is class it can implements one or more interfaces using implements clause.But option uses extends clouse
So,option 2 is wrong.
------------------
 
Ranch Hand
Posts: 2378
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Jordy,
Classes in java can extend only one another class using extends clause and can implement 0(no implements clause),1 or more interface(s) through implements clause. But interfaces can extend one or more interfaces through extends clause.
Hope this helps u.

------------------
azaman
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Quote
-----------------
Public XXXX extends something1, something2 // 1
-------------------
1. XXXX can be a class and something1, something2 cannot be classes as in Java a class cannot extend more than one class.
2. XXXX can be a class and something1, something2 cannot be interfaces as they need to be implemented and cannot be extended.
3. XXXX can be an interface and something1, something2 can also be interfaces and in that case the statement //1 is legal.
4. Incidentally in java for interfaces multiple inheritance is allowed and hence statement //1 is legal.
HTH
any comments...welcome.
tvs sundaram
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic