0% found this document useful (0 votes)
29 views2 pages

Topic: Abstract Classes, Interfaces Given

The document describes an abstract class MyClass with an abstract method calculate and a concrete method init. It also describes a subclass MyImpl that implements the calculate method by printing a message and returning 1. The main method creates an instance of MyImpl and calls init and calculate on it. The expected behavior is that it will print "Invoking calculate...".

Uploaded by

crazz1
Copyright
© © 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
0% found this document useful (0 votes)
29 views2 pages

Topic: Abstract Classes, Interfaces Given

The document describes an abstract class MyClass with an abstract method calculate and a concrete method init. It also describes a subclass MyImpl that implements the calculate method by printing a message and returning 1. The main method creates an instance of MyImpl and calls init and calculate on it. The expected behavior is that it will print "Invoking calculate...".

Uploaded by

crazz1
Copyright
© © 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
You are on page 1/ 2

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;

You might also like