• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

khalid mughal mock

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
given the following interface definition, which definitions are valid?
interface I
{
void setValue(int val);
int getValue();
}
Definition A
class A extends I {
int value;
void setValue(int val) { value = val;}
int getValue() { return value;}
}
Definition B
interface B extends I {
void increment();
}
Definition C

abstract class C implements I {
int getValue() { return 0;}
abstract void increment();
}
Definition D
interface D implements I {
void increment();
}
Definition E

class E implements I {
int value;
public void setValue(int val) { vlaue = val;}
}
Select one valid answer
i think there r two correct answers
B and C
somebody please help


 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C is wrong.because the setvalue method in interface I has not been override right!so C is wrong!
If i am missing something ple let me know.

Originally posted by sona nagee:
given the following interface definition, which definitions are valid?
interface I
{
void setValue(int val);
int getValue();
}
Definition A
class A extends I {
int value;
void setValue(int val) { value = val;}
int getValue() { return value;}
}
Definition B
interface B extends I {
void increment();
}
Definition C

abstract class C implements I {
int getValue() { return 0;}
abstract void increment();
}
Definition D
interface D implements I {
void increment();
}
Definition E

class E implements I {
int value;
public void setValue(int val) { vlaue = val;}
}
Select one valid answer
i think there r two correct answers
B and C
somebody please help


 
sona gold
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but c is an abstract class and hence need not implement all the methods of the interface
somebody please help
thx
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is wrong with option E ?
 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A is wrong beacuse a class cannot subclass an interface. It is trying to extend the interface.
B is right because an interface can extend another interface.
C is wrong because the access modifier public is missing from the methods definitions.
D is wrong because an interface can't implement anything. It can only extend other interfaces.
E is wrong because class E does not define the method getValue() from interface I. Either the method definition should be provided or class E must be declared abstract.
 
sona gold
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
permit thanks a million
i missed a very important point
silly me
just missed it
now i get it
only B is right
 
sona gold
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
E is wrong because implementation is not provided for the second method declared in the interface
int getvalue()
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parmeet, can you please elaborate point C, why public access modifier is required when the methods in interface I are not defined explicitly 'public'
Does it mean that all the interfaces methods are public by default, i thought if you don't mention any access modifier its treated as friendly.
please explain.
Thanks in advance
Jyotsna
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic