GoConqr has a new look! Let us know what you think.

Quiz

Chapter 1: Java Building Blocks

davidv 23 questions

Take the quiz

Questions in this quiz (23)

  1. 1Which of the following are valid Java identifiers? (Choose all that apply)
    1. AA. A$B
    2. BB. _helloWorld
    3. CC. true
    4. DD. java.lang
    5. EE. Public
    6. FF. 1980_s
  2. 2What is the output of the following program?
    1: public class WaterBottle {
    2: private String brand;
    3: private boolean empty;
    4: public static void main(String[] args) {
    5: WaterBottle wb = new WaterBottle();
    6: System.out.print("Empty = " + wb.empty);
    7: System.out.print(", Brand = " + wb.brand);
    8: } }
    1. AA. Line 6 generates a compiler error.
    2. BB. Line 7 generates a compiler error.
    3. CC. There is no output.
    4. DD. Empty = false, Brand = null
    5. EE. Empty = false, Brand =
    6. FF. Empty = null, Brand = null
  3. 3Which of the following are true? (Choose all that apply)
    4: short numPets = 5;
    5: int numGrains = 5.6;
    6: String name = "Scruffy";
    7: numPets.length();
    8: numGrains.length();
    9: name.length();
    1. AA. Line 4 generates a compiler error.
    2. BB. Line 5 generates a compiler error.
    3. CC. Line 6 generates a compiler error.
    4. DD. Line 7 generates a compiler error.
    5. EE. Line 8 generates a compiler error.
    6. FF. Line 9 generates a compiler error.
    7. GG. The code compiles as is.
  4. 4Given the following class, which of the following is true? (Choose all that apply)
    1: public class Snake {
    2:
    3: public void shed(boolean time) {
    4:
    5: if (time) {
    6:
    7: }
    8: System.out.println(result);
    9:
    10: }
    11: }
    1. AA. If String result = "done"; is inserted on line 2, the code will compile.
    2. BB. If String result = "done"; is inserted on line 4, the code will compile.
    3. CC. If String result = "done"; is inserted on line 6, the code will compile.
    4. DD. If String result = "done"; is inserted on line 9, the code will compile.
    5. EE. None of the above changes will make the code compile.
  5. 5Given the following classes, which of the following can independently replace INSERT
    IMPORTS HERE to make the code compile? (Choose all that apply)
    package aquarium;
    public class Tank { }
    package aquarium.jellies;
    public class Jelly { }
    package visitor;
    INSERT IMPORTS HERE
    public class AquariumVisitor {
    public void admire(Jelly jelly) { } }
    1. AA. import aquarium.*;
    2. BB. import aquarium.*.Jelly;
    3. CC. import aquarium.jellies.Jelly;
    4. DD. import aquarium.jellies.*;
    5. EE. import aquarium.jellies.Jelly.*;
    6. FF. None of these can make the code compile.
  6. 6Given the following classes, what is the maximum number of imports that can be removed
    and have the code still compile?
    package aquarium; public class Water { }
    package aquarium;
    import java.lang.*;
    import java.lang.System;
    import aquarium.Water;
    import aquarium.*;
    public class Tank {
    public void print(Water water) {
    System.out.println(water); } }
    1. AA. 0
    2. BB. 1
    3. CC. 2
    4. DD. 3
    5. EE. 4
    6. FF. Does not compile.
  7. 7Given the following classes, which of the following snippets can be inserted in place of
    INSERT IMPORTS HERE and have the code compile? (Choose all that apply)
    package aquarium;
    public class Water {
    boolean salty = false;
    }
    package aquarium.jellies;
    public class Water {
    boolean salty = true;
    }
    package employee;
    INSERT IMPORTS HERE
    public class WaterFiller {
    Water water;
    }
    1. AA. import aquarium.*;
    2. BB. import aquarium.Water;
      import aquarium.jellies.*;
    3. CC. import aquarium.*;
      import aquarium.jellies.Water;
    4. DD. import aquarium.*;
      import aquarium.jellies.*;
    5. EE. import aquarium.Water;
      import aquarium.jellies.Water;
    6. FF. None of these imports can make the code compile.
  8. 8Given the following class, which of the following calls print out Blue Jay? (Choose all that
    apply)
    public class BirdDisplay {
    public static void main(String[] name) {
    System.out.println(name[1]);
    } }
    1. AA. java BirdDisplay Sparrow Blue Jay
    2. BB. java BirdDisplay Sparrow "Blue Jay"
    3. CC. java BirdDisplay Blue Jay Sparrow
    4. DD. java BirdDisplay "Blue Jay" Sparrow
    5. EE. java BirdDisplay.class Sparrow "Blue Jay"
    6. FF. java BirdDisplay.class "Blue Jay" Sparrow
    7. GG. Does not compile.
  9. 9Which of the following legally fill in the blank so you can run the main() method from the
    command line? (Choose all that apply)
    public static void main( )
    1. AA. String[] _names
    2. BB. String[] 123
    3. CC. String abc[]
    4. DD. String _Names[]
    5. EE. String... $n
    6. FF. String names
    7. GG. None of the above.
  10. 10Which of the following are legal entry point methods that can be run from the command
    line? (Choose all that apply)
    1. AA. private static void main(String[] args)
    2. BB. public static final main(String[] args)
    3. CC. public void main(String[] args)
    4. DD. public static void test(String[] args)
    5. EE. public static void main(String[] args)
    6. FF. public static main(String[] args)
    7. GG. None of the above.

Information

Description
OCA java 8 JAVA 8 Quiz on Chapter 1: Java Building Blocks, created by davidv on 23/04/2016.
Author
davidv
Language
Español
Views
0
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?