Programming Week 10 Flashcards
5 Questions
100 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

To print the last element in the array named ar, you can write:

  • System.out.println(ar[length()-1])
  • System.out.println(ar[ar.length-1]) (correct)
  • System.out.println(ar[length-1])
  • System.out.println(ar[ar.length])
  • To print the last element in the array named ar, you can write:

  • System.out.println(ar[ar.length])
  • System.out.println(ar.length)
  • System.out.println(ar[length])
  • None of these (correct)
  • A method that has the signature void m(int[] ar):

  • can only change copies of each of the elements in the array ar
  • cannot change the values in the array ar
  • can change the values in the array ar (correct)
  • None of these
  • The ____________ relationship occurs when members of one class form a subset of another class.

    <p>is-A</p> Signup and view all the answers

    Inheritance gives your programs the ability to express _______________ between classes.

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

    Study Notes

    Array Access

    • Use System.out.println(ar[ar.length - 1]); to print the last element of the array ar.
    • Accessing ar[ar.length] is out of bounds and will result in an error.

    Method Behavior

    • Method signature void m(int[] ar) can change values in the array ar directly since arrays are reference types.

    Array Properties

    • vals.length for the 2D array vals is 4, indicating the number of arrays it contains.

    Data Types

    • The data type of num in int[] num = new int; is int, indicating an integer array.

    Constructors

    • Constructors share the same name as the class they belong to.
    • A class can have any number of constructors, allowing for different ways to instantiate objects.

    Accessor Methods

    • Accessor instance methods typically begin with "get" for returning values or "is" depending on the return type.

    Class Instantiation

    • To instantiate a Rectangle object, the correct syntax is Rectangle myRectangle = new Rectangle(10, 12);.

    Default Constructor

    • A valid default constructor for Clock is public Clock() { setTime(0, 0, 0); }.

    Public Methods

    • The method setTime(int, int, int) is public and does not return anything.

    Valid Method Calls

    • The valid set of statements to call methods on a Rectangle object is:
      • bigRect.area();
      • bigRect.perimeter();
      • bigRect.print();

    Class Relationships

    • The "is-A" relationship occurs when a subclass is a type of its superclass, indicating a hierarchy.

    Inheritance

    • Inheritance allows for the expression of relationships between classes, promoting code reuse.

    Method Overloading

    • When overloading a method in a subclass, you must change the number, type, or order of parameters.

    Constructor Requirement

    • When defining a subclass without a constructor, its superclass must either have no constructors defined or have a default (no-arg) constructor.

    UML Diagrams

    • The method toString() serves to provide a string representation of the object.

    Superclass Constructors

    • A subclass constructor with Student(String name, long id) will compile if the superclass Person has a default or no-arg constructor.

    Object Reference Output

    • The method used to print an object in the format pete is Person@addbf1 is toString().

    ArrayList Requirement

    • To use ArrayList, import the class from the java.util package.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your understanding of programming concepts with these flashcards for Week 10. Focused on printing elements from arrays, these flashcards provide both questions and definitions to enhance your learning. Perfect for students looking to reinforce their knowledge in this crucial area of programming.

    More Like This

    Mastering Arrays in Java
    14 questions
    Array Indexing
    10 questions

    Array Indexing

    GreatestFreesia avatar
    GreatestFreesia
    Array Declaration and Indexing
    13 questions
    Array Indexing Basics
    18 questions
    Use Quizgecko on...
    Browser
    Browser