WINSEM2020-21 STS3205 SS VL2020210500206 Reference Material I 18-Feb-2021 ABSTRACT CLASS IN JAVA
WINSEM2020-21 STS3205 SS VL2020210500206 Reference Material I 18-Feb-2021 ABSTRACT CLASS IN JAVA
IN
JAVA
ABSTRACT CLASS
● An abstract class is a class that is marked with the abstract keyword and cannot be
instantiated
● If a class has at least one abstract method, then the class must be declared as
abstract
NEED OF ABSTRACT CLASS
● Abstract classes are the perfect placeholder for common functionality required in
almost all of the subclasses of the abstract class
DEFINING ABSTRACT CLASS
● Any class that contains one or more abstract methods must also be declared
abstract
● an abstract class cannot be directly instantiated with the new operator
To declare an abstract method, use this general form
• First, note that Animal is marked as abstract and Walrus is not. In this
example, Walrus is considered the first concrete subclass of Animal
Any class inheriting the current class, must either override the abstract method
ABSTRACT INTERFACE
C. "X extends Y" is correct if X and Y are either both classes or both
interfaces.
D. "X extends Y" is correct for all combinations of X and Y being classes
and/or interfaces
Answer: C
QUESTION:02
A. Protected
B. Public
C. Private
D. default
Answer: B
QUESTION:03
Which statements are true for both abstract classes and interfaces?
(Choose all that apply)?
D. Both B and C
Answer: D
QUESTION:04
Which statements are true about the Concrete Class? (Choose all that
apply?
Answer: A
QUESTION:05
Which statements are true about the following code? (Choose all that apply)
Answer: D
THANK YOU