0% found this document useful (0 votes)
482 views

Modifier

The document describes an abstract class MyClass with an abstract method calculate and a concrete subclass MyImpl that implements calculate. It then creates an instance of MyImpl, calls its init and calculate methods. The expected behavior is that it will print "Invoking calculate..." when calculate is invoked on the MyImpl instance.

Uploaded by

crazz1
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
482 views

Modifier

The document describes an abstract class MyClass with an abstract method calculate and a concrete subclass MyImpl that implements calculate. It then creates an instance of MyImpl, calls its init and calculate methods. The expected behavior is that it will print "Invoking calculate..." when calculate is invoked on the MyImpl instance.

Uploaded by

crazz1
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Topic: Abstract Classes, Interfaces

Given:
1. abstract class MyClass {
2.

void init() { }

3.

abstract int calculate();

4. }
5. class MyImpl extends MyClass {
6.

int calculate() {

7.

System.out.println("Invoking calculate...");

8.

return 1;

9.

10.}
11.public class TestMyImpl {
12.

public static void main(String[] args) {

13.

MyImpl mi = new MyImpl();

14.

mi.init();

15.

mi.calculate();

16.

17.}
What is the expected behaviour?
Prints "Invoking calculate...".
Runtime error occurs.
Compilation error at line 2.
Compilation error at line 14.
Topic: Access Modifiers
Which one of the following modifiers can be applied to a method?
transient
native

volatile
friend
Topic: Access Modifiers
Given a method in a class, what access modifier do you use to restrict
access to that method to only the other members of the same class?
static
private
protected
volatile
Topic: Access Modifiers
Which of the following modifiers can be applied to a constructor?
protected
static
synchronized
transient
Topic: Access Modifiers
Which of the following member level (i.e. nonlocal) variable declarations
will not compile?
transient int b = 3;
public static final int c;
volatile int d;
private synchronized int e;
Topic: Access Modifiers
Which of the following modifiers can be applied to the declaration of a
field?
abstract
volatile
native
synchronized

You might also like