Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Super Keyword

Worksheet

Consider the following classes.

public class First public class Second extends First public class Third extends Second
{ { {
public void methodOne() public void methodOne() public void methodOne()
{ { {
System.out.print("1"); super.methodOne(); System.out.print("X");
} System.out.print("A"); super.methodOne();
} }
public void methodTwo()
{ public void methodTwo() public void methodTwo()
methodOne(); { {
System.out.print("2"); super.methodTwo(); System.out.print("Y");
} System.out.print("B"); super.methodTwo();
} }
} } }
Assume the following declarations.

First f1 = new First();


First f2 = new Second();
First f3 = new Third();

What is the output of the following client code segments?

1. f1.methodOne(); ________
2. f1.methodTwo(); ________
3. f2.methodOne(); ________
4. f2.methodTwo(); ________
5. f3.methodOne(); ________
6. f3.methodTwo(); ________

You might also like