Assignment 3: questions
What is unusual about an abstract method? A. no method body B. no parameter list C. no return type D. nothing
A
What is an abstract class? What is its purpose?
An abstract class is a class that cannot be instantiated but that can be the parent of other classes. Its purpose is to be a parent to several related classes. The advantage of using an abstract class is that you can group several related classes together as siblings.
An abstract class in Java usually contains one or more abstract A. constructors B. methods C. variables D. None
B
How do we use an interface in our classes? A. Using the extends keyword B. Using the implements keyword C. Using the instanceof keyword D. Using the interface keyword
B
What is the output of the below Java program with an abstract class? abstract class Coffee { Coffee() { System.out.println("Inside Constructor of Coffee.."); } } class ColdCoffee extends Coffee { ColdCoffee() { System.out.println("Inside Constructor of ColdCoffee.."); } } public class AbstractClassTesting { public static void main(String[] args) { ColdCoffee cf = new ColdCoffee(); } } A. Compiler error B. Inside Constructor of Coffee.. Inside Constructor of ColdCoffee.. C. Inside Constructor of ColdCoffee.. D. Inside Constructor of Coffee..
B
When a class implements an interface it must A. overload all the methods in the interface B. Provide all the nondefault methods that are listed in an interface, with the exact signatures and return types specified C. not have a constructor D. be an abstract class
B
Which of the following is the operator used to determine whether an object is an instance of particular class? A. equals B. instanceof C. isA D. >>
B
All Interface methods in Java are __ by default A. publicB B. abstract C. public and abstract D. None of the above
C
All Interface variables are _ by default in java A. public B. final C. public and final D. None
C
An abstract class in Java can be created using the keyword A. final B. interface C. abstract D. static
C
What is garbage collection in java? A. The operating system periodically deletes all of the java files available on the system. B. Any package imported in a program and not used is automatically deleted. C. When all references to an object are gone, the memory used by the object is automatically reclaimed. D. The JVM checks the output of any Java program and deletes anything that doesn't make sense. E. When all references to an object are gone the memory used by the object is not reclaimed.
C
__ When all references to an object are gone, the memory used by the object is automatically reclaimed.
C
Choose a correct statement about Java Interfaces? A. Interface contains only abstract methods by default. B. A Java class can implement multiple interfaces C. An Interface can extend or inherit another Interface. D. All the above
D
Choose a correct statement about abstract classes? A. An abstract class can extend a concrete class B. An abstract class can extend another abstract class C. An abstract class can implement any number of interfaces. D. All the above.
D
How do we instantiate an abstract class? A. through inheritance B. using the new keyword C. using the abstract keyword D. we can't
D
Polymorphism A. Refers to the ability of two or more objects belonging to different classes to respond to exactly the same message in different class-specific ways B. Simplifies code maintenance C. Does not simplifies code maintenance D. Refers to the ability of two or more objects belonging to different classes to respond to exactly the same message in different class-specific ways and simplifies code maintenance.
D
T/F? The following code snippet is valid? public abstract class A { public abstract void load(); } public class B extends A { public abstract void load(); }
F
T/F? Can you create an object from an abstract class in Java?
F
T/F? A class may implement at most one interface
F
T/F? Abstract methods must be implemented in the first subclass?
F
T/F? An abstract class cannot have abstract child classes.
F
T/F? An abstract class must have non-abstract methods.
F
T/F? To create an Abstract class, the keyword "class" is also required.
T
T/F? The following code snippet is valid? public abstract class A { public abstract void load(); } public abstract class B extends A { public abstract void load(String payload); }
T
T/F? We use overridden methods in polymorphism?
T
T/F? You can use super(...) to access a constructor of an abstract parent class if the parameters match by corresponding type
T
What conditions are required for the use of polymorphism?
The classes are in the same hierarchy. All subclasses override the same method(s). A subclass object reference is assigned to a superclass object reference. The superclass object reference is used to call the overridden method.