Java Study Group Chapter 1

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By K_electron
K
K_electron
Community Contributor
Quizzes Created: 1 | Total Attempts: 59
Questions: 5 | Attempts: 59

SettingsSettingsSettings
Java Study Group Chapter 1 - Quiz


This is for our Java study group.


Questions and Answers
  • 1. 

    What is the correct order?

    • A.

      Import, package, class

    • B.

      Class, import, package

    • C.

      Package, import, class

    • D.

      Package, class, import

    • E.

      Import, class, package

    Correct Answer
    C. Package, import, class
    Explanation
    The correct order is package, import, class. In Java, the package statement is used to define the package that the class belongs to. The import statement is used to import other classes or packages that are needed in the current class. Finally, the class statement is used to define the class itself. Therefore, the correct order is to first define the package, then import any necessary classes or packages, and finally define the class.

    Rate this question:

  • 2. 

    A class can ...

    • A.

      Extend only a single class and implement only a single interface

    • B.

      Extend only a single class but implement multiple interfaces

    • C.

      Extend multiple classes but implement only a single interface

    • D.

      Extend multiple classes and implement multiple interfaces

    Correct Answer
    B. Extend only a single class but implement multiple interfaces
    Explanation
    A class can extend only a single class because Java does not support multiple inheritance for classes. However, it can implement multiple interfaces because Java allows a class to implement multiple interfaces to achieve multiple inheritance-like behavior.

    Rate this question:

  • 3. 

    Which of the following are Java keywords?

    • A.

      Goto

    • B.

      Malloc

    • C.

      Implementable

    • D.

      Extends

    • E.

      New

    • F.

      Delete

    Correct Answer(s)
    A. Goto
    D. Extends
    E. New
  • 4. 

    Which are true?

    • A.

      Abstract interfaces can have final methods.

    • B.

      The first concrete subclass must implement all abstract methods of its superclass.

    • C.

      Abstract classes cannot have static methods.

    • D.

      Interfaces can declare instance variables.

    • E.

      A protected method in a superclass that is inherited by a subclass in a different package is now available to all classes in the subclass's package.

    Correct Answer(s)
    B. The first concrete subclass must implement all abstract methods of its superclass.
    C. Abstract classes cannot have static methods.
    Explanation
    The first statement is true. When a class extends an abstract class, it must provide implementations for all the abstract methods defined in the superclass.

    The second statement is also true. Abstract classes cannot have static methods because static methods are associated with the class itself, not with any particular instance of the class.

    Therefore, the correct answer is that the first concrete subclass must implement all abstract methods of its superclass and abstract classes cannot have static methods.

    Rate this question:

  • 5. 

    Given the following classes defined in separate files:What will the output be on running the Test class?

    • A.

      Compiler error for statement v=c

    • B.

      Prints: -Vehicle:Driving--Car:Driving--Vehicle:Driving-

    • C.

      Runtime exception for statement v=c

    • D.

      Prints: -Vehicle:Driving--Car:Driving--Car:Driving-

    • E.

      Prints: -Vehicle:Driving--Car:Driving-

    Correct Answer
    D. Prints: -Vehicle:Driving--Car:Driving--Car:Driving-
    Explanation
    The output will be "Prints: -Vehicle:Driving--Car:Driving--Car:Driving-". This is because the statement "v=c" assigns the object of the Car class to the reference variable v of the Vehicle class. Since the Car class is a subclass of the Vehicle class, it inherits the drive() method from the Vehicle class. Therefore, when the drive() method is called on the object v, it executes the drive() method of the Car class. The output is printed three times because the drive() method is called three times in the Test class.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Jun 05, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 26, 2010
    Quiz Created by
    K_electron
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.