A class constant is created using the keyword final. It can't be changed. A static variable is
instantiated once for the entire class, but it can be changed. - ANS-Static variables are stored
only once for all instances of the class. A class constant is equivalent to it.
True
By using the keyword static, you not longer have to instantiate an object of the class in order to
access it's methods. An example of this is the math library, where you would access the
methods without actually instantiating a math object. - ANS-A static data method can access
static variable as well as be invoked without an object.
True
If a class is abstract it means it can't be instantiated, but one of the great aspects of an abstract
class over an interface is that it allows the programmer to create methods that are common to
all derived classes. - ANS-An abstract class can have abstract and non-abstract methods.
False
An interface defines what the methods must be implemented by a class implementing the
interface. It defines the protocol for calling the method, but it does not actually have methods. -
ANS-An interface can have abstract and non-abstract methods.
False
Java does not support multiple inheritance in classes. - ANS-An abstract class supports multiple
inheritance
True
Technically, you could argue java doesn't support multiple inheritance, but interfaces do a close
job of approximating it. You are not really wrong if you answered this question as F. - ANS-An
interface supports multiple inheritance
True
, This is just a good definition to know. I didn't specifically cover this in class, but added it here to
let you know it if you haven't studied it closely. - ANS-An abstract class can have final, non-final,
static and non-static variables.
False
So honestly, this is something I wouldn't have known. Only static and final variables can be
created for an interface. I haven't had a need to declare one, but if you do interface variables
are static because Java interfaces cannot be instantiated in their own right; the value of the
variable must be assigned in a static context in which no instance exists. The final modifier
ensures the value assigned to the interface variable is a true constant that cannot be
re-assigned by program code. Just thought this would round out the discussion. - ANS-An
interface can have final, non-final, static and non-static variables.
True
An abstract class can have many types of methods. Again, an abstract class just means the
class can't be instantiated into an object - ANS-An abstract class can have static methods, a
main method, and a constructor.
False
Interfaces only declare the prototype for a method, not the method itself. - ANS-An interface can
have static methods, a main method, and a constructor.
True
Abstract classes can implement methods. As long as all the methods with the right prototypes
are declared, then the abstract class can implement the interface. - ANS-An abstract class can
provide the implementation of an interface.
False
Interfaces do not provide an implementation of any classes, they define what methods classes
that implement them must implement. - ANS-An interface can provide the implementation of an
abstract class
The accelerate() method defined in ElectricCar will be called.
This is a straight inheritance question. Since TeslaModelS is an object instantiated from the
ElectricCar class, the method assoicated with ElectricCar is called. - ANS-A class Car and its
subclass ElectricCar both have a method accelerate() which was written by the programmer as
part of the class definition. If TeslaModelS refers to an object of type ElectricCar, what will the
following code do?
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller topgradesdr. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $7.99. You're not tied to anything after your purchase.