• Post Reply Bookmark Topic Watch Topic
  • New Topic

please help answer the mcq  RSS feed

 
shoeb sattar
Greenhorn
Posts: 14
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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!
 
pankaj saxena
Ranch Hand
Posts: 47
C++ Java
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • 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: 56599
172
  • Mark post as helpful
  • send pies
  • 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]
 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edited to remove answers
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • 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.
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siddhesh, Giving away direct answers is not the norm here.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • 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: 56599
172
  • Mark post as helpful
  • send pies
  • 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: 56599
172
  • Mark post as helpful
  • send pies
  • 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.
 
Rajeev Trikha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
In 1st ques.... I think E is also correct
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!