• 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

please help answer the mcq

 
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interface Base {
boolean m1 ();
byte m2(short s);

}


Which code fragments will compile? (Choose all that apply.)
A. interface Base2 implements Base { }
B. abstract class Class2 extends Base { public boolean m1() { return true; } }
C. abstract class Class2 implements Base { }
D. abstract class Class2 implements Base {public boolean m1() { return (true); } }
E. class Class2 implements Base { boolean m1() { return false; } byte m2(short s) { return 42; } }
 
shoeb sattar
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which is true? (Choose all that apply.)



A. "X extends Y" is correct if and only if X is a class and Y is an interface.
B. "X extends Y" is correct if and only if X is an interface and Y is a class.
C. "X extends Y" is correct if X and Y both are classes or both are interfaces.
D. "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's an "mcq"?

In any case, what do *you* think the answers are, and why? Let's start there.

And welcome to JavaRanch!
 
Ranch Hand
Posts: 47
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edited to remove direct answer. We try to provide direction, and try to help people learn how to learn--not just give out answers. Please see DoYourOwnHomework.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MCQ is of course Multiple Choice Question.

As people will see from the "Beginning Java" title page, simply giving out answers helps nobody, so thank you David for deleting that post.
Please tell us what you think the correct answer is, and let us see what we think about it.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I earlier wrote:MCQ is of course Multiple Choice Question.

[pedantic mode]But those are not MCQs; they are true-false questions.[/pedantic mode]
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edited to remove answers
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As noted in a response above, we do not give out direct answers due to our do your own homework policy.
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Siddhesh, Giving away direct answers is not the norm here.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To avoid any more direct answers, I shall close this thread. I am pulling rank.

Shoeb Sattar: please PM me with what you think are the correct answers, in a format like "1a 1c 2b 2c 2d", then I shall reopen the thread and you can post them and we shall all see what we think of them.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I, yesterday wrote:Shoeb Sattar: please PM me . . . then I shall reopen the thread . . .

No reply, no thread opening.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
He replied saying "B" is correct for the first question.

"B" will compile, but the answer is not complete. this is not an MCQ (where there is one correct and 4 wrong answers) but a true-false, so I wasn't simply being pedantic. There may be more than one correct answer.

Please supply your answer for the 2nd question.
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you work on the second question first then it would be clear that 'B' cannot be part of the answer to question 1.
 
shoeb sattar
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In 1st ques.... I think E is also correct
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
shoeb sattar, welcome to JavaRanch.

When you post a question from a book, mock exam or other source, it is required on JavaRanch that you QuoteYourSources - in other words, please tell us where you copied the question from.
 
Rajeev Trikha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shoeb,

With a question like this it is very easy to compile it and see the answer. If you did compile E then you will learn something about 'weaker access privilege'. That should take you into understanding rules for method overriding.
 
Rajeev Trikha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Incidentally I should have also mentioned that in an interface all the methods are implicitly public and abstract whilst all the variables public static and final. This applies whether you state it or not in the definition.

One of the Java rules about method overriding is that you cannot assign weaker privilege to an overridden method. Imagine people invoked your method in good faith that it implements a public method but only to discover that it isn't so in the implementing class. The compiler will never allow you to break a contract.
 
reply
    Bookmark Topic Watch Topic
  • New Topic