Java Test 1
A(n) _________ enables a program to read data from the user.
Scanner
What will be the output after the following Java statements have been executed? int a = 4, b = 12, c = 37, d = 51; if ( a < b) System.out.println( "a < b" ); if ( a > b) System.out.println( "a > b" ); if ( d <= c) System.out.println( "d <= c" ); if ( c != d) System.out.println( "c != d" );
a < b c != d
Which of the following data items are arranged from the smallest to the largest in the data hierarchy.
bits, characters, fields, records, files
Which of the primitive data types store floating-point numbers?
double and float
What is the purpose of the arithmetic operator below?%
to obtain the remainder
What is the value of result after the following Java statements execute? int a = 4, b = 12, c = 37, d = 51, result; result = d % a * c + a % b + a;
119
What will be the output of the following code? int a = 5; int b = 2; int c = a / b; System.out.printf("%d", c);
2
Which of the following code would create an instance object of a class with two parameters? A. Student stud = new Stud("John Smith", 45); B. Student stud = new Stud(String name, int age); C. Student stud = Stud("John Smith", 45); D. None of the choices.
A. Student stud = new Stud("John Smith", 45);
Which of the following statements would declare 4 integer variables? A. int a = 10, b = 5, c = 10, d; d = 10; B. None of the choices. C. int a; b; int c; int d; D. int a = 10; b = 5; c = 10; d; d = 10;
A. int a = 10, b = 5, c = 10, d; d = 10;
Which of the following would declare an integer variable myGrade with a default value of 20? A. int myGrade; B. int myGrade = 20; C. int mygrade = 20; D. myGrade = 20;
B. int myGrade = 20;
Which of the following statements would print a string and keep the cursor in the same line? A. String message = 'Hello World'; System.out.print(message); B. int message = "Hello World"; System.out.print(message); C. String message = "Hello World"; System.out.print(message); D. String message = "Hello World"; System.out.println(message);
C. String message = "Hello World"; System.out.print(message);
Which of the following statements would display the phrase Java is fun? A. System.out.println("Java is \nfun"); B. System.out.println("\"Java is fun\""); C. System.out.println("Java is fun"); D. System.out.println('Java is fun');
C. System.out.println("Java is fun");
What is the output of the following code? System.out.print("Hello "); System.out.println("World"); A. HelloWorld B. World Hello C. Hello World D. Hello World
D. Hello World
Which of the following is not one of the six logical units of a computer? A. Output unit B. Input unit C. Central processing unit D. Printer
D. Printer
Which of the following is not one of the three types of computer languages? A. High-Level Languages B. Assembly language C. Machine Language D. Spoken Languages
D. Spoken Languages
The following snippet code has an error, how would you fix it? //find monthly payment public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; monthlyPayment = loanAmount * monthlyInterestRate / (1 - (1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12))); //return monthlyPayment; }
by removing the commented line in the return value
What is the main purpose of mutator and accessors (getters and setters) in Java?
to safely manipulate data from one class to another class.
Which of the following is not a relational or equality operator? A. =! B. == C. > D. <=
A. !=
Today, virtually all new major operating systems are written in:
C or C++
Which of the following statement would create a constructor for an Student class? A. public void Student() { this.name = name; } B. public void Student(String name) { this.name = name; } C. public Student(String name) { this.name = name; } D. public Student() { this.name = name; }
C. public Student(String name) { this.name = name; }
Which of the following is a valid variable declaration? A. //variable declaration B. public static void sum(); C. import java.util.*; D. int total;
D. int total;
A default constructor has now many parameters?
0
The format specifier (identifier) _________ is a placeholder for an int value?
%d
Which of the following does not contain a syntax error? A. System.out.println(Hello World!"); B. System.out.println("Hello World!"); C. System.out.println('Hello World!'): D. System.out.println("Hello World!");
D. System.out.println("Hello World!");