IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
Author

please help answer the mcq

shoeb sattar
Greenhorn

Joined: Feb 05, 2010
Messages: 3

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; } }

This message was edited 1 time. Last update was at by Bear Bibeault

shoeb sattar
Greenhorn

Joined: Feb 05, 2010
Messages: 3

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.

This message was edited 2 times. Last update was at by shoeb sattar

David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 6852

What's an "mcq"?

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

And welcome to JavaRanch!

This message was edited 1 time. Last update was at by David Newton


Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
pankaj saxena
Greenhorn

Joined: Nov 21, 2009
Messages: 4

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.

This message was edited 1 time. Last update was at by David Newton

Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14987

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
Bartender

Joined: Oct 13, 2005
Messages: 14987

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
Greenhorn

Joined: Mar 05, 2009
Messages: 23

Edited to remove answers

This message was edited 2 times. Last update was at by David Newton


Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd (SCJP 6 )
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Messages: 486

As noted in a response above, we do not give out direct answers due to our do your own homework policy.

SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Messages: 167

Siddhesh, Giving away direct answers is not the norm here.
Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14987

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
Bartender

Joined: Oct 13, 2005
Messages: 14987

I, yesterday wrote:Shoeb Sattar: please PM me . . . then I shall reopen the thread . . .
No reply, no thread opening.
Campbell Ritchie
Bartender

Joined: Oct 13, 2005
Messages: 14987

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

Joined: Jan 29, 2010
Messages: 79

If you work on the second question first then it would be clear that 'B' cannot be part of the answer to question 1.

Rajeev Trikha (SCJP 6)
shoeb sattar
Greenhorn

Joined: Feb 05, 2010
Messages: 3

In 1st ques.... I think E is also correct
Jesper Young
Java Cowboy
Bartender

Joined: Aug 16, 2005
Messages: 7862

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.

Java Beginners FAQ - JavaRanch SCJP FAQ
The Java Tutorial - Java SE 6.0 API documentation
Rajeev Trikha
Ranch Hand

Joined: Jan 29, 2010
Messages: 79

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 (SCJP 6)
Rajeev Trikha
Ranch Hand

Joined: Jan 29, 2010
Messages: 79

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.

Rajeev Trikha (SCJP 6)
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
JProfiler
Get rid of your performance problems and memory leaks!

.