Java 8 Associate Flashcards
Which of the following are valid Java identifiers?
- A$B
- _helloWorld
- true
- java.lang
- Public
- 1980_s
_helloWorld
What 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: } }
Which 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();
Given 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: }
Given 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) { } }
import aquarium.;
import aquarium..Jelly;
import aquarium.jellies.Jelly;
import aquarium.jellies.;
import aquarium.jellies.Jelly.;
None of these can make the code compile.
Given 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); } }
Given 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;
}
import aquarium.;
import aquarium.Water;import aquarium.jellies.;
import aquarium.;import aquarium.jellies.Water;
import aquarium.;import aquarium.jellies.*;
import aquarium.Water;import aquarium.jellies.Water;
None of these imports can make the code compile.
Given 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]);
} }
java BirdDisplay Sparrow Blue Jay
java BirdDisplay Sparrow “Blue Jay”
java BirdDisplay Blue Jay Sparrow
java BirdDisplay “Blue Jay” Sparrow
java BirdDisplay.class Sparrow “Blue Jay”
java BirdDisplay.class “Blue Jay” Sparrow
Does not compile.
Which 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()
String[] _names
String[] 123
String abc[]
String _Names[]
String… $n
String names
None of the above.
Which of the following are legal entry point methods that can be run from the command line? (Choose all that apply)
private static void main(String[] args)
public static final main(String[] args)
public void main(String[] args)
public static void test(String[] args)
public static void main(String[] args)
public static main(String[] args)
None of the above.
Which of the following are true? (Choose all that apply)
An instance variable of type double defaults to null.
An instance variable of type int defaults to null.
An instance variable of type String defaults to null.
An instance variable of type double defaults to 0.0.
An instance variable of type int defaults to 0.0.
An instance variable of type String defaults to 0.0.
None of the above.
Which of the following are true? (Choose all that apply)
A local variable of type boolean defaults to null.
A local variable of type float defaults to 0.
A local variable of type Object defaults to null.
A local variable of type boolean defaults to false.
A local variable of type boolean defaults to true.
A local variable of type float defaults to 0.0.
None of the above.
Which of the following are true? (Choose all that apply)
An instance variable of type boolean defaults to false.
An instance variable of type boolean defaults to true.
An instance variable of type boolean defaults to null.
An instance variable of type int defaults to 0.
An instance variable of type int defaults to 0.0.
An instance variable of type int defaults to null.
None of the above.
Given the following class in the file /my/directory/named/A/Bird.java:
INSERT CODE HERE
public class Bird { }
Which of the following replaces INSERT CODE HERE if we compile from /my/directory? (Choose all that apply)
package my.directory.named.a;
package my.directory.named.A;
package named.a;
package named.A;
package a;
package A;
Does not compile.
Which of the following lines of code compile? (Choose all that apply)
int i1 = 1_234;
double d1 = 1234.0;
double d2 = 1_234._0;
double d3 = 1234.0;
double d4 = 1_234.0;
None of the above.