Class design Flashcards

1
Q

Inheritance

A

Inheritance is the process by which the new child subclass automatically includes any public or protected primitives, objects, or methods defned in the parent class.

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

Java supports single inheritance, by which a class may inherit from only one direct parent class.

A

Java doesn’t support multiple inheritance!

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

Java allows only one public class per file

A

true

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

public access modifer

A

The public access modifer applied to a class indicates that it can be referenced and used in any class.

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

default package private modifer

A

The default package private modifer, which is the lack of any access modifer, indicates the class can be accessed only by a subclass or class within the same package.

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

java.lang.Object

A
java.lang.Object is the only class that doesn’t have any
parent classes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
The first statement of every constructor is a call to another constructor within the class
using this(), or a call to a constructor in the direct parent class using super().
A

true

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

The super() call may not be used after the first statement of the constructor.

A

true

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

If no super() call is declared in a constructor, Java will insert a no-argument super()
as the first statement of the constructor.

A

true

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

If the parent doesn’t have a no-argument constructor and the child doesn’t define any constructors, the compiler will throw an error and try to insert a default no-argument constructor into the child class.

A

true

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

If the parent doesn’t have a no-argument constructor, the compiler requires an explicit
call to a parent constructor in each child constructor

A

true

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

Hiding Static Methods

A

A hidden method occurs when a child class defnes a static method with the same name and signature as a static method defned in a parent class.

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

Overriding vs. Hiding Methods

A

Unlike overriding a method, in which a child method
replaces the parent method in calls defned in both the parent and child, hidden methods only replace parent methods in the calls defned in the child class.

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

final methods cannot be overridden.

A

true

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

Hiding Variables

A

When you hide a variable, you defne a variable with the same name as a variable in a parent class.
This creates two copies of the variable within an instance of the child class: one instance defned for the parent reference and another defned for the child reference.

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

abstract class

A

An abstract class is a class that is marked with the abstract keyword and cannot be instantiated

17
Q

abstract method

A

An abstract method is a method marked with the abstract keyword defned in an abstract class, for which no implementation is provided in the class in which it is declared.

18
Q

an abstract method may only be defned in an abstract class.

A

+

19
Q

concrete class

A

A concrete class is the frst nonabstract subclass that extends an abstract class and is required to implement all inherited abstract methods.

20
Q

A class may implement multiple interfaces, each separated by a comma

A

+

21
Q

interface

A

An interface is an abstract data type that defnes a list of abstract public methods that any class implementing the interface must provide.

22
Q

a class can implement an interface, a class cannot extend an interface.

A

but

an interface can extend another interface, an interface cannot implement another interface.

23
Q

Interface variables

A

Interface variables are assumed to be public, static, and final

24
Q

The value of an interface variable

A

The value of an interface variable must be set when it is declared since it is marked as final.

25
Q

Default Interface Methods

A

A default method is a method defned within an

interface with the default keyword in which a method body is provided

26
Q

Static Interface Methods

A

A static method defned in an interface is not inherited in any classes that implement the interface.

27
Q

Any field in an interface is implicitly public, static, and final, whether these keywords are specified or not.

A

+

28
Q

varialbles are hidden, methods are overriden.

A

true

29
Q

a interface can have static method but method must have body in that case

A

+

30
Q

Overriding a Method

A

You can override a method a method by declaring a new method with the signature and return type as the method in the parent class.

When you override a method, you may reference the parent version of the method using the super keyword.

31
Q

Hiding Variables

A

When you hide a variable, you defne a variable with the same name as a variable in a parent class. This creates two copies of the variable within an instance of the child class:
one instance defned for the parent reference and another defned for the child reference.

32
Q

Fields defined in an interface are ALWAYS considered as public, static, and final. Even if you don’t explicitly define them as such.

A

+

33
Q

An interface method cannot be default and static at the same time because a default method is always an instance method.

A

+

34
Q

Trying to override a static method with a non-static method (and vice-versa) in a class will result in a compilation error.

A

+