Quiz5_92932.pdf

April 14, 2014
Java Quiz 5
Sharif University of Technology
Name :
Student Id :
1. What are the features of abstract classes? What is their usage in inheritance?
2. Define the following access levels (A brief answer is acceptable)
a) protected
b) friendly
3. Which pair of access modifiers are plausible for the question marks?
(for each “?” , choose among public,private,protected or nothing)
class A
{
? void f()
{
}
}
class B extends A
{
@Override
? void f()
{
}
}
1
4. Why do the following pieces of code result in an error?
a) class A
{
public A(int a)
{
System.out.println("a");
}
}
class B extends A
{
public B(int a)
{
System.out.println("b");
super(a);
}
}
b)
class A
{
public A(int a)
{
System.out.println("a");
}
}
class B extends A
{
public B(int a)
{
System.out.println("b");
}
}
5. (Bonus Question) What is the output of the following code?
class Base {
String className = "Base";
}
class Derived extends Base {
private String className = "Derived";
}
public class PrivateMatter {
public static void main(String[] args) {
System.out.println(new Derived().className);
}
}
2