🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Java Programming: Calling Methods
34 Questions
0 Views

Java Programming: Calling Methods

Created by
@RiskFreeAustin

Podcast Beta

Play an AI-generated podcast conversation about this lesson

Questions and Answers

In the Date class, which method should be used to change the value of the instance variable 'day'?

  • setDay() (correct)
  • changeDay()
  • updateDay()
  • getDay()
  • For object 'birthday' of the Date class, what is the correct way to retrieve the month using an accessor method?

  • int month = birthday.getMonthValue();
  • int theMonth = birthday.setMonth();
  • int month = birthday.retrieveMonth();
  • int theMonth = birthday.getMonth(); (correct)
  • How many instance variables are there in the Date class?

  • 4
  • 2
  • 3 (correct)
  • 1
  • Which type of method is the getMonth() method in the Date class?

    <p>Accessor method</p> Signup and view all the answers

    To complete the setDay() method in the Date class, what parameter should be passed?

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

    What should be returned by the getDay() method in the Date class?

    <p>'day'</p> Signup and view all the answers

    What will be the output of the code snippet provided?

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

    Which of the following expressions will evaluate to false?

    <p>game instanceof Soccer</p> Signup and view all the answers

    Which statement will generate a compilation error?

    <p>System.out.println(title.toUpperCase())</p> Signup and view all the answers

    Which of the following statements will cause a compilation error?

    <p>Resizable shape = new Resizable(){};</p> Signup and view all the answers

    Given the declaration Resizable circle = new Circle(5.5);, which of the following statements will compile successfully?

    <p>circle.resize(3.0);</p> Signup and view all the answers

    'InstanceOf' operator in Java is used for:

    <p>Checking if an object is an instance of a particular class or interface</p> Signup and view all the answers

    What is the output of the program segment in the given text?

    <p>Opening datafile.txt...Reading data...Done.</p> Signup and view all the answers

    What should be inserted in the missing statement in method openFile() to prompt the user for a valid file name?

    <p>inputFile = new Scanner(new File(in.next()));</p> Signup and view all the answers

    Which exception is caught by the catch block in Practice 7.19 if an IOException occurs?

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

    What happens if the file in Practice 7.20 contains only two integer values instead of three?

    <p>InputMismatchException is generated.</p> Signup and view all the answers

    In Practice 7.18, what happens if 'datafile.txt' does not exist?

    <p>A FileNotFoundException occurs.</p> Signup and view all the answers

    What does 'array = array + array;' in the text do?

    <p>Produces an error due to invalid syntax.</p> Signup and view all the answers

    What will be the output of the code segment processing input one character at a time using a Scanner object?

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

    In the second code segment processing an input file one line at a time, what is the purpose of the condition 'if (Character.isDigit(input.charAt(0)))'?

    <p>To check if the first character of each line is a digit</p> Signup and view all the answers

    If the delimiter used in the third code segment breaks the string 'apple,orange,banana' into three tokens, what would be the value of 'count' printed at the end?

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

    What is the significance of 'data.useDelimiter(""")' in the third code segment?

    <p>It sets the delimiter to be a double quote</p> Signup and view all the answers

    If 'data.hasNextLine()' returns false in the second code segment, what can be inferred?

    <p>All lines in the input file have been processed</p> Signup and view all the answers

    What does 'count++' signify in all three code segments?

    <p>'count' increments for each line read from the input file</p> Signup and view all the answers

    Which method call is illegal using a reference variable of the BaseballPlayer class?

    <p>player1.setBattingAvg(.258);</p> Signup and view all the answers

    Which method is overridden in the BaseballPlayer class?

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

    How can private superclass variables be accessed in subclass methods in Java?

    <p>Using public getters for the private variables in the superclass</p> Signup and view all the answers

    How can you call an overridden superclass method within a subclass method in Java?

    <p>By using the super keyword followed by the method name</p> Signup and view all the answers

    What statement completes the display() method in the BaseballPlayer class to include superclass properties?

    <p>System.out.println(super.getName() + &quot; &quot; + super.getSalary());</p> Signup and view all the answers

    Which statement correctly invokes the superclass constructor from the BaseballPlayer class constructor?

    <p>super(theName, theSalary);</p> Signup and view all the answers

    Consider class Soccer as a subclass of Sport. Which assignment of objects is invalid?

    <p>Soccer mySport = new Sport();</p> Signup and view all the answers

    What will be printed when this statement is executed within a Java code segment: BaseballPlayer bp = new BaseballPlayer(); bp.display();?

    <p>&quot;null 0 0&quot;</p> Signup and view all the answers

    What will be printed when this Java code segment is executed: Player p = new BaseballPlayer(); p.display();?

    <p>It will call Player's display method.</p> Signup and view all the answers

    What happens when p.display() is called where Player p = new Player();?

    <p>It will print Player's display information.</p> Signup and view all the answers

    More Quizzes Like This

    Java Programming Vocabulary Quiz
    20 questions
    Java Programming Chapters 1-3 Quiz
    78 questions
    Java Programming Test 1 Flashcards
    26 questions
    Java Programming Chapter 11 Quiz
    8 questions

    Java Programming Chapter 11 Quiz

    WellConnectedComputerArt avatar
    WellConnectedComputerArt
    Use Quizgecko on...
    Browser
    Browser