Podcast
Questions and Answers
A class from which you cannot create objects is called a/an ____.
A class from which you cannot create objects is called a/an ____.
If a class has an abstract method, which of the following statements is NOT true?
If a class has an abstract method, which of the following statements is NOT true?
A class that cannot be instantiated is called a/an ____.
A class that cannot be instantiated is called a/an ____.
A class that inherits an abstract method but does not override it ____.
A class that inherits an abstract method but does not override it ____.
Signup and view all the answers
Which of the following statements about abstract classes is NOT true?
Which of the following statements about abstract classes is NOT true?
Signup and view all the answers
Which of the following statements about abstract classes is NOT true?
Which of the following statements about abstract classes is NOT true?
Signup and view all the answers
Which of the following statements about abstract classes and interfaces is NOT true?
Which of the following statements about abstract classes and interfaces is NOT true?
Signup and view all the answers
Which of the following statements about abstract methods is true?
Which of the following statements about abstract methods is true?
Signup and view all the answers
A method that has no implementation is called a/an ____ method.
A method that has no implementation is called a/an ____ method.
Signup and view all the answers
A class that implements Comparable has to at least have how many methods?
A class that implements Comparable has to at least have how many methods?
Signup and view all the answers
A class that implements Locatable has to at least have how many methods?
A class that implements Locatable has to at least have how many methods?
Signup and view all the answers
All methods located inside of an interface are automatically set with what access?
All methods located inside of an interface are automatically set with what access?
Signup and view all the answers
All methods located inside of an interface are automatically labeled with which of the following modifiers?
All methods located inside of an interface are automatically labeled with which of the following modifiers?
Signup and view all the answers
Which of the following could fill ? in 'public interface Testable { }'?
Which of the following could fill ? in 'public interface Testable { }'?
Signup and view all the answers
Which of the following could not fill ? in 'public interface Testable { }'?
Which of the following could not fill ? in 'public interface Testable { }'?
Signup and view all the answers
Which of the following could fill ? in 'public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { ... }'?
Which of the following could fill ? in 'public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { ... }'?
Signup and view all the answers
Assuming ? is filled correctly, which of the following could fill ? in 'public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { ... }'?
Assuming ? is filled correctly, which of the following could fill ? in 'public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { ... }'?
Signup and view all the answers
Assuming ? is filled correctly, which of the following could fill ? in 'public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { ... }'?
Assuming ? is filled correctly, which of the following could fill ? in 'public interface Locatable { int getX(); public abstract int getY(); double getSpeed(); } public class Ship implements Locatable { ... }'?
Signup and view all the answers
All variables located inside of an interface are automatically set with what access?
All variables located inside of an interface are automatically set with what access?
Signup and view all the answers
All variables located inside of an interface are automatically labeled with which of the following modifiers?
All variables located inside of an interface are automatically labeled with which of the following modifiers?
Signup and view all the answers
Which of the following could fill ? in 'public interface Variable { }'?
Which of the following could fill ? in 'public interface Variable { }'?
Signup and view all the answers
Which of the following could fill ? in 'public interface Variable { }'?
Which of the following could fill ? in 'public interface Variable { }'?
Signup and view all the answers
What type of variable is variable s in 'public interface Skeleton { String s = "Check it Yo!"; }'?
What type of variable is variable s in 'public interface Skeleton { String s = "Check it Yo!"; }'?
Signup and view all the answers
An interface can extend another _________________.
An interface can extend another _________________.
Signup and view all the answers
A class can implement how many other interfaces?
A class can implement how many other interfaces?
Signup and view all the answers
An interface can extend how many other interfaces?
An interface can extend how many other interfaces?
Signup and view all the answers
An interface can extend how many other classes?
An interface can extend how many other classes?
Signup and view all the answers
What is the minimum number of methods a class extending abstract class Demo could have?
What is the minimum number of methods a class extending abstract class Demo could have?
Signup and view all the answers
What is the minimum number of methods a class extending abstract class Demo could have?
What is the minimum number of methods a class extending abstract class Demo could have?
Signup and view all the answers
What is printed when you type System.out.println(ticketInfo); after you do the above declarations?
What is printed when you type System.out.println(ticketInfo); after you do the above declarations?
Signup and view all the answers
How many elements are in ticketInfo?
How many elements are in ticketInfo?
Signup and view all the answers
Which of the following sets the value for the 3rd row and 2nd column of a 2D array called nums?
Which of the following sets the value for the 3rd row and 2nd column of a 2D array called nums?
Signup and view all the answers
What is the value at seatingInfo after the code above executes?
What is the value at seatingInfo after the code above executes?
Signup and view all the answers
What is the value of name after the code above executes?
What is the value of name after the code above executes?
Signup and view all the answers
How many rows does a have if it is created as follows int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};?
How many rows does a have if it is created as follows int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};?
Signup and view all the answers
How many columns does a have if it is created as follows int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};?
How many columns does a have if it is created as follows int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};?
Signup and view all the answers
How would you get the value 6 out of the following array int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};?
How would you get the value 6 out of the following array int[][] a = {2, 4, 6, 8}, {1, 2, 3, 4};?
Signup and view all the answers
Given the following code segment, what is the value of sum after this code executes?
Given the following code segment, what is the value of sum after this code executes?
Signup and view all the answers
Which index is the last element in an arraylist called nums at?
Which index is the last element in an arraylist called nums at?
Signup and view all the answers
Which of the following is the correct way to get the first value in a list called nums?
Which of the following is the correct way to get the first value in a list called nums?
Signup and view all the answers
Which of the following is the correct way to set the second value in a list called nums to 5?
Which of the following is the correct way to set the second value in a list called nums to 5?
Signup and view all the answers
Which of the following is the correct way to remove the value 3 from the list nums = [5, 3, 2, 1]?
Which of the following is the correct way to remove the value 3 from the list nums = [5, 3, 2, 1]?
Signup and view all the answers
Which of the following is the correct way to add 2 between the 1 and 3 in the following list nums = [1, 3, 4]?
Which of the following is the correct way to add 2 between the 1 and 3 in the following list nums = [1, 3, 4]?
Signup and view all the answers
Study Notes
Abstract Classes
- An abstract class cannot be instantiated and may contain methods without an implementation.
- A class with an abstract method cannot allow object creation. Only subclasses must implement abstract methods.
- A class that inherits an abstract method but does not override it must also be marked as abstract.
Interfaces
- Interfaces can only have public and abstract methods. All methods declared in an interface are public by default.
- An interface can extend another interface but not a class. Interfaces can also define variables that are public static final by default.
Methods and Variables in Abstract Classes and Interfaces
- An abstract method has a name, parameters, and a return type but lacks a concrete implementation.
- A variable declared in an interface is inherently public, and all variables are static and final.
- Only public and private constructors are permissible in abstract classes.
Implementation Requirements
- A class that implements the Comparable interface must define at least one method:
compareTo()
. - To implement the Locatable interface, a class must define methods for
getX()
,getY()
, andgetSpeed()
.
Array and 2D Array Operations
- Declaring an array without initialization gives it a value of null.
- To access a specific element in a 2D array, the syntax uses row and column indices, denoted as
array[row][column]
.
Lists and ArrayList Operations
- The last index of an ArrayList is found using
nums.size() - 1
. - The correct method to add, remove, or retrieve items in a list is using
add(index, value)
,remove(index)
, andget(index)
respectively.
Constructors in Abstract Classes
- A derived class from an abstract class must implement at least one abstract method if such methods exist.
- Constructors in abstract classes can be public or private, but must adhere to access modifier rules.
Summary of Key Points
- Abstract classes and interfaces provide a foundational structure for building complex programs and enforcing design contracts.
- Understanding the mechanics of methods, variables, and array manipulations is crucial for effective programming in languages that support these constructs.
- Knowing how to manipulate lists and use correct syntax for method calls is essential for maintaining and optimizing code functionality.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your understanding of abstract classes and methods in Object-Oriented Programming with this quiz. Each flashcard presents a concept related to unit 8, focusing on the ability to create objects and inheritance rules.