OOP Flashcards

1
Q

Is the constructor inherited?

A

No, the constructor is not inherited.

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

Can you make the constructor final?

A

No, the constructor cannot be final. In fact constructors can only take access modifiers. They cannot be abstract, final, native, static, or synchronized.

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

T/F: You can use the keyword “this” anywhere in a constructor.

A

False. The keyword “this” must be used on the first line. The keyword “super” has this rule as well.

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

T/F: The Java compiler will add a call to super() in your constructor if you do not have a call to super.

A

TRUE! super() is automatically added if missing. The call to super must be the first line in the constructor. Also if the super class does not have a no-argument constructor, you will get a compile-time error.

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

Can you execute a program without a main() method?

A

Yes, but you must use a version of the JDK older than 1.7 and use a static block. Starting with JDK 1.7 you will get an error.

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

What is the difference between aggregation and composition?

A

In aggregation, the child objects have their own lifecycle and can exist without the parent. In composition, the child objects do have their own lifecycle and should NOT exist without their parent.

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

What is the difference between an argument vs a parameter?

A

“Parameters” refers to the list of variables in a method declaration. Arguments are the actual values that are passed in when the method is invoked.

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

Can you use this() and super() both in a constructor?

A

No, because both statements MUST be the FIRST statement in the constructor.

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

Can you overload the main() method?

A

Yes. But but when running a class from the command line, java will select the main() method with the standard signature.

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

Can you override a static method?

A

No. Static methods are part of the class, not the object instance.

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

What is a covariant return type?

A

Starting with Java 1.5, you can override a method by changing the return type so that it is a subclass of the original method’s return type. E.g. the overriden method could return a Circle instead of a Shape. Before Java 1.5, the method signature had match arguments and return type exactly.

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

Can you instantiate an abstract class?

A

No, abstract classes cannot be instantiated, they can only be extended.

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

What is a marker interface?

A

A marker interface is an interface that has no data members or methods.

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

Can an abstract class have a constructor?

A

Yes

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