nerdexam
Oracle

1Z0-803 · Question #191

Which two items can legally be contained within a java class declaration?

The correct answer is B. A field declaration D. A method declaration. This question assesses knowledge of the fundamental components that can legally reside within a Java class declaration.

Java Basics

Question

Which two items can legally be contained within a java class declaration?

Options

  • AAn import statement
  • BA field declaration
  • CA package declaration
  • DA method declaration

How the community answered

(23 responses)
  • A
    4% (1)
  • B
    91% (21)
  • C
    4% (1)

Why each option

This question assesses knowledge of the fundamental components that can legally reside within a Java class declaration.

AAn import statement

Import statements must appear at the top of a Java source file, after an optional package declaration and before any class, interface, or enum declarations.

BA field declarationCorrect

Field declarations, which define the member variables of a class, are legally contained within the curly braces of a class declaration. They represent the state of an object.

CA package declaration

A package declaration must be the very first statement in a Java source file, preceding any import statements and all type declarations.

DA method declarationCorrect

Method declarations, which define the behaviors or functions of a class, are legally contained within the curly braces of a class declaration. They represent actions an object can perform.

Concept tested: Java class structure components

Source: https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-8.1.6

Topics

#class structure#syntax#fields#methods

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice