Podcast
Questions and Answers
Which of the following statements about the IntCalculator are correct? (Select all that apply)
Which of the following statements about the IntCalculator are correct? (Select all that apply)
- The inner braces are not needed. (correct)
- The outer braces are not needed. (correct)
- The new keyword is not needed. (correct)
- The statement does not end with a semicolon. (correct)
What is the term for a variable whose value is never changed, but it isn't declared with the final key word?
What is the term for a variable whose value is never changed, but it isn't declared with the final key word?
- Effectively final variable (correct)
- Virtually constant variable
- Default variable
- Anonymous inner variable
What is the special type of expression used to create an object that implements a functional interface?
What is the special type of expression used to create an object that implements a functional interface?
- Beta
- Alpha
- Sigma
- Lambda (correct)
Which of the following is an example of a lambda expression?
Which of the following is an example of a lambda expression?
When an 'is a' relationship exists between objects, it means that the specialized object has:
When an 'is a' relationship exists between objects, it means that the specialized object has:
Which of the following statements declares Salaried as a subclass of PayType?
Which of the following statements declares Salaried as a subclass of PayType?
If ClassA extends ClassB, then:
If ClassA extends ClassB, then:
In an inheritance relationship:
In an inheritance relationship:
In UML diagrams, inheritance is shown:
In UML diagrams, inheritance is shown:
What keyword can you use to call a superclass constructor explicitly?
What keyword can you use to call a superclass constructor explicitly?
What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); }}
What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); }}
Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { public ClassB() { super(10); }}
Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { public ClassB() { super(10); }}
If a subclass constructor does not explicitly call a superclass constructor:
If a subclass constructor does not explicitly call a superclass constructor:
The super statement that calls the superclass constructor:
The super statement that calls the superclass constructor:
Replacing inadequate superclass methods with more suitable subclass methods is known as what?
Replacing inadequate superclass methods with more suitable subclass methods is known as what?
If two methods have the same name but different signatures, they are:
If two methods have the same name but different signatures, they are:
Look at the following code. The method in line ________ will override the method in line ________.
Look at the following code. The method in line ________ will override the method in line ________.
Look at the following code. Which line will cause a compiler error?
Look at the following code. Which line will cause a compiler error?
When a subclass overloads a superclass method:
When a subclass overloads a superclass method:
A protected member of a class may be directly accessed by:
A protected member of a class may be directly accessed by:
When declaring class data members, it is best to declare them as:
When declaring class data members, it is best to declare them as:
If you do not provide an access specifier for a class member, the class member is given ________ by default.
If you do not provide an access specifier for a class member, the class member is given ________ by default.
When a method is declared with the ________ modifier, it cannot be overridden in a subclass.
When a method is declared with the ________ modifier, it cannot be overridden in a subclass.
If ClassC extends ClassB, which extends ClassA, this would be an example of:
If ClassC extends ClassB, which extends ClassA, this would be an example of:
Look at the following code. Which method1 will be executed as a result of the following statements? ClassA item1 = new ClassC(); item1.method1();
Look at the following code. Which method1 will be executed as a result of the following statements? ClassA item1 = new ClassC(); item1.method1();
Look at the following code. Which line will cause a compiler error? ClassB item1 = new ClassA(); item1.method1();
Look at the following code. Which line will cause a compiler error? ClassB item1 = new ClassA(); item1.method1();
If a class contains an abstract method:
If a class contains an abstract method:
Given the following code which of the following is TRUE? public class ClassB implements ClassA{}
Given the following code which of the following is TRUE? public class ClassB implements ClassA{}
All fields declared in an interface:
All fields declared in an interface:
Look at the following code. Which line has an error? public interface Interface1 { int FIELDA = 55; public int methodA(double){} }
Look at the following code. Which line has an error? public interface Interface1 { int FIELDA = 55; public int methodA(double){} }
Look at the following code. Which line in ClassA has an error? public interface MyInterface { int FIELDA = 55; public int methodA(double); } public class ClassA implements MyInterface { FIELDA = 60; public int methodA(double) { } }
Look at the following code. Which line in ClassA has an error? public interface MyInterface { int FIELDA = 55; public int methodA(double); } public class ClassA implements MyInterface { FIELDA = 60; public int methodA(double) { } }
Look at the following code. What is missing from ClassA? public interface MyInterface { int FIELDA = 55; public int methodA(double); } public class ClassA implements MyInterface { FIELDA = 60; public int methodB(double) { } }
Look at the following code. What is missing from ClassA? public interface MyInterface { int FIELDA = 55; public int methodA(double); } public class ClassA implements MyInterface { FIELDA = 60; public int methodB(double) { } }
When one object is a specialized version of another object, there is this type of relationship between them.
When one object is a specialized version of another object, there is this type of relationship between them.
A subclass can directly access:
A subclass can directly access:
In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC
In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC
A subclass may call an overridden superclass method by:
A subclass may call an overridden superclass method by:
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC
In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC
In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC
In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC
What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println('This is the last statement in the constructor.'); }}
What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println('This is the last statement in the constructor.'); }}
In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println('This is the last statement in the constructor.'); }}
In the following code, what will the call to super do? public class ClassB extends ClassA { public ClassB() { super(40); System.out.println('This is the last statement in the constructor.'); }}
If a superclass does not have a default constructor or a no-arg constructor:
If a superclass does not have a default constructor or a no-arg constructor:
Look at the following code. The method in line ________ will override the method in line ________.
Look at the following code. The method in line ________ will override the method in line ________.
Look at the following code. Which line will cause a compiler error? public class ClassA { public ClassA() {} public int method1(int a){} public final int method2(double b){} } public class ClassB extends ClassA { public ClassB(){} public int method1(int b){} public int method2(double c){} }
Look at the following code. Which line will cause a compiler error? public class ClassA { public ClassA() {} public int method1(int a){} public final int method2(double b){} } public class ClassB extends ClassA { public ClassB(){} public int method1(int b){} public int method2(double c){} }
Protected members are:
Protected members are:
Protected class members are denoted in a UML diagram with the symbol:
Protected class members are denoted in a UML diagram with the symbol:
Which of the following is TRUE about protected access?
Which of the following is TRUE about protected access?
Like a family tree, a ________ shows the inheritance relationship between classes.
Like a family tree, a ________ shows the inheritance relationship between classes.
In a class hierarchy:
In a class hierarchy:
Look at the following code: Which method1 will be executed when the following statements are executed? ClassA item1 = new ClassB(); item1.method1();
Look at the following code: Which method1 will be executed when the following statements are executed? ClassA item1 = new ClassB(); item1.method1();
Look at the following code: Which method will be executed when the following statements are executed? ClassC item1 = new ClassA(); item1.method1();
Look at the following code: Which method will be executed when the following statements are executed? ClassC item1 = new ClassA(); item1.method1();
If a class contains an abstract method:
If a class contains an abstract method:
In an interface all methods have:
In an interface all methods have:
Which of the following statements correctly specifies three interfaces?
Which of the following statements correctly specifies three interfaces?
This annotation tells the Java compiler that a method is meant to override a method in the superclass.
This annotation tells the Java compiler that a method is meant to override a method in the superclass.
What is required for an interface method that has a body?
What is required for an interface method that has a body?
An anonymous inner class must:
An anonymous inner class must:
Study Notes
Inheritance and Object Relationships
- An "is a" relationship indicates that the specialized object inherits all characteristics of the general object along with additional traits.
- Subclass relationships in Java are established using the
extends
keyword, which creates a hierarchical structure. - In an inheritance relationship, the superclass constructor executes before the subclass constructor to ensure proper initialization.
Constructor Behavior
- Java requires that a call to the superclass constructor using the
super
keyword must be the first statement in the subclass constructor. - If a subclass constructor doesn't explicitly call a superclass constructor, Java automatically invokes the superclass's default or no-arg constructor before executing the subclass constructor.
Method Overriding and Overloading
- Method overriding occurs when a subclass provides a specific implementation for a method already defined in its superclass.
- Method overloading happens when multiple methods in the same class share the same name but differ in parameter types or counts.
- Access levels to superclass methods vary: protected members can be accessed by subclasses, while private members cannot.
Access Modifiers
- Members declared as
protected
can be accessed by the same package classes but also by subclasses in different packages. - By default, if no access modifier is given for a class member, it has package-private visibility.
Abstract Classes and Interfaces
- An abstract class cannot be instantiated, and any subclass must implement its abstract methods.
- Methods in an interface are implicitly public and abstract unless declared otherwise.
- Interfaces in Java can be implemented by classes, which must provide concrete definitions for the interface methods.
UML Diagrams and Class Hierarchies
- In UML, inheritance is represented by a line with an open arrowhead pointing to the superclass, illustrating the parent-child relationship.
- A class hierarchy visually represents the inheritance relationships between classes, with more general classes positioned at the top.
Exception Handling within Classes
- Compiler errors may arise when method signatures in subclasses conflict with final methods in superclasses or due to incorrect method accessibility.
- A class implementing an interface must follow the rules laid out by the interface, specifically regarding method definitions and access.
Lambda Expressions and Anonymous Classes
- A lambda expression is a concise way to represent a function that implements a functional interface, enabling cleaner code.
- Anonymous inner classes can be used to provide implementations of interfaces or extend classes without the need for a separate named class.
Key Terms and Definitions
- The
@Override
annotation indicates that a method is intended to override a method from a superclass. - Variables that remain unchanged after initialization but are not marked as
final
are referred to as effectively final variables.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your understanding of object-oriented programming concepts through these flashcards. Focus on the 'is a' relationships and their implications in class hierarchies. Ideal for students learning programming principles.