• 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

from javacertificate.com

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is the question
public interface Material
{
}
public interface Instrument{
public void play();
}

public class Piano implements Instrument, Material {
public void play() {
System.out.println ("Playing the piano");
}
public static void main(String[] args) {
Instrument inst = new Piano();
inst.play();
}
}
Answers
1. Compilation succeeds, no output is produced.
2. Compilation succeeds, the output is Playing the Piano
3. Compilation fails, Piano cannot implement 2 interfaces
4. Compilation fails, interface Material does not have any methods defined
5. Compilation fails, interface Instrument does not have an implementation for the play() method

the answer is 2,
but i am getting the error
Piano.java:1: class Material is public, should be declared in a file named Mater
ial.java
public interface Material
^
Piano.java:4: class Instrument is public, should be declared in a file named Ins
trument.java
public interface Instrument{
^
2 errors
can u help me?
thanks...
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There can be only one public class/interface in a file and the file must be named the same.
If more than one class/interface is declared public, compiler will throw error.
But none of the answer choices given are correct.
I guess u won't get such kind of questions in the real exam.
[ May 06, 2003: Message edited by: Rajeshwari Natarajan ]
 
Sri Rao
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thnaks very much Rajeshwari
Regards
Sri
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the question doesn't specify that all the classes and interfaces are in the same file, then I think you can assume that they are defined properly, I mean, they are all in different files.
Then the answer 2 will be correct.
[ May 06, 2003: Message edited by: Vidya Ram ]
 
stable boy
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While creating the questions we have assumed exactly what Vidya Ram is saying. If not stated differently inside the question then you may assume that they are placed inside a different.
However as discussed before we are updating the questions and for all new questions we are adding the statement explicitly that both classes/interfaces are defined in seperate source files.
Thomas De Vos
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic