Object-Oriented Programming Unit 8
43 Questions
100 Views

Object-Oriented Programming Unit 8

Created by
@TenaciousFeynman9892

Questions and Answers

A class from which you cannot create objects is called a/an ____.

  • Abstract class (correct)
  • Non-inheritable class
  • Concrete class
  • Static class
  • If a class has an abstract method, which of the following statements is NOT true?

  • You cannot construct an object from this class.
  • You cannot inherit from this class.
  • All non-abstract subclasses of this class must implement this method.
  • You can construct an object from this class. (correct)
  • A class that cannot be instantiated is called a/an ____.

  • Non-inheritable
  • Abstract class (correct)
  • Anonymous class
  • Concrete class
  • A class that inherits an abstract method but does not override it ____.

    <p>Must be declared as an abstract class.</p> Signup and view all the answers

    Which of the following statements about abstract classes is NOT true?

    <p>You can declare a class as abstract only when it contains all abstract methods.</p> Signup and view all the answers

    Which of the following statements about abstract classes is NOT true?

    <p>A class cannot be declared as abstract if it has no abstract methods.</p> Signup and view all the answers

    Which of the following statements about abstract classes and interfaces is NOT true?

    <p>Both abstract classes and interfaces can have instance variables.</p> Signup and view all the answers

    Which of the following statements about abstract methods is true?

    <p>An abstract method has a name, parameters, and a return type, but no code in the body of the method.</p> Signup and view all the answers

    A method that has no implementation is called a/an ____ method.

    <p>abstract</p> Signup and view all the answers

    A class that implements Comparable has to at least have how many methods?

    <p>1</p> Signup and view all the answers

    A class that implements Locatable has to at least have how many methods?

    <p>3</p> Signup and view all the answers

    All methods located inside of an interface are automatically set with what access?

    <p>public</p> Signup and view all the answers

    All methods located inside of an interface are automatically labeled with which of the following modifiers?

    <p>abstract</p> Signup and view all the answers

    Which of the following could fill ? in 'public interface Testable { }'?

    <p>public double getScore();</p> Signup and view all the answers

    Which of the following could not fill ? in 'public interface Testable { }'?

    <p>private void setScore(double s);</p> 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 { ... }'?

    <p>A, B, and C</p> 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 { ... }'?

    <p>public</p> 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 { ... }'?

    <p>Locatable s = new Ship(3,5,7.8);</p> Signup and view all the answers

    All variables located inside of an interface are automatically set with what access?

    <p>public</p> Signup and view all the answers

    All variables located inside of an interface are automatically labeled with which of the following modifiers?

    <p>A and C only</p> Signup and view all the answers

    Which of the following could fill ? in 'public interface Variable { }'?

    <p>double y = 99;</p> Signup and view all the answers

    Which of the following could fill ? in 'public interface Variable { }'?

    <p>final double y = 99;</p> Signup and view all the answers

    What type of variable is variable s in 'public interface Skeleton { String s = "Check it Yo!"; }'?

    <p>class</p> Signup and view all the answers

    An interface can extend another _________________.

    <p>interface</p> Signup and view all the answers

    A class can implement how many other interfaces?

    <p>as many as you want</p> Signup and view all the answers

    An interface can extend how many other interfaces?

    <p>as many as you want</p> Signup and view all the answers

    An interface can extend how many other classes?

    <p>0</p> Signup and view all the answers

    What is the minimum number of methods a class extending abstract class Demo could have?

    <p>1</p> Signup and view all the answers

    What is the minimum number of methods a class extending abstract class Demo could have?

    <p>1</p> Signup and view all the answers

    What is printed when you type System.out.println(ticketInfo); after you do the above declarations?

    <p>null</p> Signup and view all the answers

    How many elements are in ticketInfo?

    <p>6</p> 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?

    <p>nums[3][1] = 5;</p> Signup and view all the answers

    What is the value at seatingInfo after the code above executes?

    <p>Luke</p> Signup and view all the answers

    What is the value of name after the code above executes?

    <p>Maria</p> 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};?

    <p>2</p> 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};?

    <p>4</p> 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};?

    <p>a[0][2];</p> Signup and view all the answers

    Given the following code segment, what is the value of sum after this code executes?

    <p>8</p> Signup and view all the answers

    Which index is the last element in an arraylist called nums at?

    <p>nums.size() - 1</p> Signup and view all the answers

    Which of the following is the correct way to get the first value in a list called nums?

    <p>nums.get(0);</p> 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?

    <p>nums.set(1, 5);</p> 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]?

    <p>nums.remove(1);</p> 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]?

    <p>nums.add(1, 2);</p> 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(), and getSpeed().

    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), and get(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.

    Quiz Team

    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.

    More Quizzes Like This

    Java Abstract Classes
    18 questions
    Abstract Class Overview in Programming
    9 questions
    Java Abstract Classes Flashcards
    5 questions

    Java Abstract Classes Flashcards

    WellConnectedComputerArt avatar
    WellConnectedComputerArt
    Use Quizgecko on...
    Browser
    Browser