• 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

Quiz

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
Sorry i missed here the point all classes in an Interface are
public and abstract!
- Thanks
 
Destroy anything that stands in your way. Except this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic