Valid Java Method Implementations

0% found this document useful (0 votes)
201 views2 pages
The document contains code snippets and questions about interfaces and classes in Java. The first code snippet shows an interface with a method and a class implementing that interface. The valid option to replace "xx" is "void doSomething() { }" as it properly defines and implements the interface method. The second snippet shows another interface with a method and implementing class. The valid option to replace "xxxxxx" is "public void draw() { }" as it is the legal definition and implementation of the interface method. The third snippet shows a Count interface with a method and counter field, and a TestCount class implementing it. The main method creates a TestCount object and calls its countUp method. The

Uploaded by

crazz1
License
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Given the code below:

interface MyInterface {
void doSomething ( ) ;
}
class MyClass implements MyInterface {
// xx
}
Choose the valid option that can be substituted in place of xx in the MyClass class .
public native void doSomething ( ) ;
void doSomething ( ) { /* valid code fragments */ }
private void doSomething ( ) { /* valid code fragments */ }
protected void doSomething ( ) { /* valid code fragments */ }
interface I1 {
void draw();
}
class C implements I1 {
xxxxxx
}
Which of the following when inserted at xxxxxx is a legal definition and
implementation ?
void draw() { }
public void draw() { }
protected void draw() { }
abstract void draw() { }
Given the following,
1. interface Count {
2.

short counter = 0;

3.

void countUp();

4. }
5. public class TestCount implements Count {
6.
7.

public static void main(String [] args) {

8.

TestCount t = new TestCount();

9.

[Link]();

10. }
11. public void countUp() {
12.

for (int x = 6; x>counter; x--, ++counter) {

13.
14.

[Link](" " + counter);


}

15. }
16. }
What is the result?
123
0123
1234
Compilation fails

You might also like