1. What does a Java compiler do?
Select one:
a. Runs Java programs
b. Translates byte code in ".class" files into machine
language
c. Translates source code in ".class" files into
machine language
d. Translates source code in ".java" files into Java
byte code in ".class" files
e. Translates source code in ".java" files into machine
language
2. A subclass will _____ one superclass.
Select one:
a. abstract
b. extend
c. implement
d. inherit
e. override
3. Consider the following line of Java code.
System.out.println("Hello, World!");
Which one of the following does NOT describe '"Hello,
World!"'?
Select one:
a. a declaration
b. an expression
c. a literal
d. a parameter
e. a statement
4.Consider the following line of Java code.
System.out.println("Hello, World!");
"System" is which of the following?
Select one:
a. a class
b. a method (subroutine)
c. an object
d. a parameter
e. a statement
5.What is the output of the following Java program?
interface Food {
public void printFlavor();
}
class Pepper extends Food {
public void printFlavor() {
System.out.println("spicy"); }
}
public class Lunch {
public static void main(String[]
args) {
Food pepper = new Pepper();
pepper.printFlavor();
}
}
Select one:
a. bland
b. bland
spicy
c. no output
d. spicy
e. the program does not compile
6.Consider the following Java program, which one of the
following best describes "pepper"?
public class Food {
static int count;
private String flavor = "sweet";
Food() { count++; }
void setFlavor(String s) { flavor =
s; }
String getFlavor() { return flavor;
}
static public void main(String[]
args) {
Food pepper = new Food();
System.out.println(pepper.getFlavor());
}
}
Select one:
a. an object
b. a reference
c. null
d. sweet
e. The program does not compile.
7. Which one of the following does NOT describe an
ArrayList?
Select one:
a. It can be used in a for-each loop.
b. It has a numbered sequence of elements.
c. It provides efficient random access to its elements.
d. Its elements can be a primitive type.
e. The number of its elements can change.
8. In a while loop, how many times does the continuation
condition run?
Select one:
a. At least once, at the beginning of each iteration.
b. At least once, at the end of each iteration.
c. Exactly once.
d. Zero or more times, at the beginning of each
iteration.
e. Zero or more times, at the end of each iteration.
The answer to questions is as follows:
1.The answer to the first question is Translates source code in
".java" files into Java
byte code in ".class" files
2. The answer to the second question is inherit
3. The answer to the third question is a declaration
4. The answer to the fourth question is a class
5. The answer to the fifth question is spicy
6. The answer to the sixth question is sweet
7. The answer to the seventh question is Its elements can be a primitive type.
8. The answer to the eight question is Zero or more times, at
the beginning of each
iteration.
1. What does a Java compiler do? Select one: a. Runs Java programs b. Translates byte...
What is the output of the following Java program? class Food { void flavor() { System.out.println("bland"); } } class Pepper extends Food { void flavor() { System.out.println("spicy"); } } public class Lunch { public static void main(String[] args) { Pepper lunch = new Food(); lunch.flavor(); } } Select one: a. bland b. bland spicy c. spicy d. the program does not compile e. no output
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...
Question 1 Not yet answered Marked out of 1.00 Flag question Question text Which of the following keywords is useful for skipping to the next iteration of a loop? Select one: a. do b. break c. switch d. continue e. while Clear my choice Question 2 Not yet answered Marked out of 1.00 Flag question Question text Consider the following line of Java code. System.out.println("Hello, World!"); "out" is which of the following? Select one: a. a statement b. a class...
JAVA LANGUAGE In Java, single text characters are represented by what data type? Which of the following statements about constructors are true? Circle all that apply. a) A class can have many methods but only one constructor. b) A constructor can be used instead of fields to represent the data inside a class. c) A constructor wastes memory in the computer so it should be used sparingly. d) A constructor is a special method that creates an object and initializes...
Write in Java! Do NOT write two different programs for Deck and Card, it should be only one program not 2 separate ones!!!!!! The Learning Goal for this exercise is to use and understand and know the difference between arrays and array lists. !!!!Use at least one array defined in your code and two array lists defined by the operation of your code!!!! The array should be 52 elements and contain a representation of a standard deck of cards, in...
Java questions
QUESTION 8 Assume the following classes are each defined in their own java files and compile public class A public void display { System.out.println("A's display"); public class B extends A{ public void display { System.out.println("B's display"); public class C extends A public void display { System.out.println("C's display"); public class D { public static void main(String args) { 3: int i = ((int)(Moth.random(* 10)) if (i == 0) a = new BO: else if (i == 1) a =...
java 1. Write a method header on line three with the following specs: Returns: a boolean Name: beTrue Parameters: none public class Main { { return true; } } 2. Write a method header on line two with the following specs: Returns: a String Name: makeCapital Parameters: a String named "name" You should not be writing code on any line other than #2 public class Main { { String ans = name.toUpperCase();...
Topics: About Java What is a compiler, and what does it do? Characteristics of the languageStrongly typed and statically typed Everything has a data type & data types must be declared Case sensitive Object oriented System.out.print() vs. System.out.println() How to use the Scanner class to obtain user input Data typesWhat are they? Know the basic types like: int, double, boolean, String, etc. Variables What is a variable? Declarations Initialization Assignment Constants Reserved words like: What is a reserved word? Examples:...
Part III. Common String Errors The following two example programs demonstrate common errors that often occur when programming with Strings. public class StringErrors1 { public static void main(String [] args) { String greeting = "hello world"; greeting.toUpperCase(); System.out.println(greeting); } } Type above code in Dr. Java or Eclipse. Compile and run the program a few times. What does this program do? How might you make the program more user-friendly? Now run the program two more...
In Java Create a testing class that does the following to the given codes below: To demonstrate polymorphism do the following: Create an arraylist to hold 4 base class objects Populate the arraylist with one object of each data type Code a loop that will process each element of the arraylist Call the first ‘common functionality’ method Call the second ‘common functionality’ method Call the third ‘common functionality’ method Verify that each of these method calls produces unique results Call...