Inheritance Flashcards

1
Q

What is an abstract method?

A

It is one that describes a behavior but does not implement it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can an interface field be declared as private?

A

No.

Interface fields are always public, static and final.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

T/F: Interface fields are always public, static and final.

A

True, even if not explicitly defined as such.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can an overriding method change the return type if it is a primitive value?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can an overriding method change to return type of an Object?

A

Yes, but only to a subclass of the return type.

This is a covariant return.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Access to static and instance fields and static methods depends on ______ .

A

the class of the reference variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T/F: access to static methods and fields depends on the actual object being pointed to

A

False.

This is the opposite of instance methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Will the following code compile?

class Super {  }
class Sub extends Super {  }
public class TestClass{
   public static void main(String[] args){
      Super s1 = new Super(); //1
      Sub s2 = new Sub();     //2
      s1 = (Super) s2;        //3
   }
}
A

Yes.

There is no issue here. A sub class can always be assigned to a super class variable without any cast.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

T/F: The native keyword can only be used on methods.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can the native keyword be used on variables.

A

No.

It can only be used on classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can the default keyword appear for a method in an abstract class?

A

No.

The default keyword can only occur for a method in an interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

T/F: Members of an interface (fields and methods) may be abstract.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can an interface method be default and static?

A

No.

The default method is always an instance method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If an interface redeclares a default method, can it provide a different implementation?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can an interface redeclare a default method AND make it abstract?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can a static method be abstract?

A

No.

17
Q

Can an interface have a static method?

A

Yes, but it must have a method body.

18
Q

T/F: A default method does not need a method body.

A

False.

A default method needs a method body.

19
Q

T/F: All fields in an interface are implicitly public, static, and final.

A

True.

These keywords need not even be specified for it to be so.

20
Q

Can a superclass reference be assigned to a subclass type?

A

Yes, but it will only have access to the parts of the object defined by the superclass.

21
Q

What determines which overridden method gets invoked in the case of instance methods?

A

The actual object.