Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quiz

 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 8.
A String Class
1.is final
2.is public
3.is serializable
4.has a constructor which takes a StingBuffer Object as an Argument
I think ans is 1,2,3. But answer given also includes 4???

Question 9.

public interface AQuestion
{
void someMethod();
}
The class which implements AQuestion
1.Should have someMethod which must necessarily be public.
2.Should have someMethod which could be "friendly" or public
3.Should have someMethod which should not throw any checked exceptions.
4.Should have someMethod which cannot be sychronized as sychronized is not in the signature of the interface defination
i think answer is only 3, but answer given also includes 1???
Please correct me if i am wrong.
- Thanks
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi;
JSK 1.3 documentation does have a constructor for String that uses a StringBuffer:

String(StringBuffer buffer)
Allocates a new string that contains the sequence of characters currently contained in the string buffer argument.

So it does look as if all four responses are right.
If you try to compile a class that implements the AQuestion interface that declares someMethod() as:
<pre>
void someMethod(){
System.out.println("I'm public");
}
</pre>
You get a compile error:

AnswerQuestion.java:1: someMethod() in AnswerQuestion cannot implement someMethod() in AQuestion; attempting to assign weaker access privileges; was public public class AnswerQuestion implements AQuestion{
^
1 error

No access modifier would mean the method would only have package access which is weaker than public access. Believe there's a rule that states you cannot implement an Interface method with weaker access than the original.
You have to declare it as:
<pre>
public void someMethod(){}
</pre>
Hope that helps.
 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
Sorry i missed here the point all classes in an Interface are
public and abstract!
- Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic