• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/30

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

30 Cards in this Set

  • Front
  • Back

What members of base class can't be inherited?

1) private members; 2) members with default access if the child class is in a different package; 3) constructors of the class. A child class cannot inherit but can call the constructors of the base class.

Describe how hiding a base class variable by a child class works

An instance or class variable is defined with the same name in the child class as in the base class. That's the variable value that will be used.

Can polymorphic methods also be called overriden?

Yes, they can.

Can you cast a base class to a child class?

No, you cannot, however, this code will still compile, but will throw a run-time exception.

What peculiar feature of interface methods do you need to remember when implementing them?

That their methods are implicitly public.

When implementing an interface's method what access modifiers are allowed?

Only public, because all methods of an interface are public by nature.

What is the complication of assigning an object of child class to a variable of parent class?

With inheritance, instance variables bind at compile time, so they will be the parent class variables, while methods bind at run time, so the child class methods implementation will be used. This makes such code very tricky.

Can you create instance objects from abstract classes?

No, code will not compile

Can you skip implementing methods in child classes inherited from abstract classes?

No, you have to implement abstract methods in derived classes, otherwise code will not compile. The only exception is when the derived class is itself abstract.

How do you implement abstract methods inherited from base classes?

You don't need to specify abstract, but the method signature should be same, including return type and arguments, then add body, even if that body is empty.

Can you define abstract methods inside non-abstract classes?

No , code will not compile.

Can abstract classes have non-abstract methods?

Yes, methods in abstract classes do not by default become abstract. They are abstract if they don't have a body. Empty body of curly braces is still a body.

How is an interface different from an abstract class?

1) An interface can only define abstract methods and constants, while abstract classes can have non-abstract methods and instance variables defined. 2) An interface

Can abstract classes and interfaces be declared private?

Yes, they can, but most likely they would be nested inside the class that makes use of them.

Do you have to initialize variables of interfaces?

Yes, because implicitly all variables in interfaces are public static and final, they need to be initialized to a value.

Describe how overriding a method of base class by a child class works

The programmer writes different implementation of the method with the same name

What's the rule for super() method when extending a parent class and defining a constructor?

If there is not explicit call to parent constructor, then a default no-argument super() is executed as the first line of the child constructor.

Can an interface extend another interface?

Yes

Can you narrow the accessibility of methods implemented from an interface?

No, they should be public as well as they are in an interface.

Can you declare a method of child class that looks exactly like the method from parent class?
Yes
Can you override a parent method in a child class by adding "throws some exception"?
No, that causes a compiler error.
Can you override a parent method with a child method that has a less restrictive access modifier?
Yes. But you cannot override a parent method with child method that has a more restrictive access modifier.
Is there an access modifier called default?
No, but there can be default interface methods
What is a default interface method?
Default method can only be defined in an interface, and has a code block with some default implementation. That is different from basic interface methods, which are abstract and therefore don't have a code block. The method however is still public in terms of access.
What does it mean to exhibit encapsulation?
A class must have all private variables. Setters are not required for a class to show encapsulation, but they are allowed.
What does it mean to exhibit immutability?
A class must have only private variables and no setters.
Can abstract classes declare public static final variables?
Yes, and so can abstract classes.
Does casting an object modify it in memory?
No
Does the type of the object determine which properties exist within the object in memory
Yes (according to exam)
Can an interface declare static methods?
Yes, as of Java 8