Programming 11: Java Assesement Exam

  • AP Computer Science A
  • Oracle Java Certification
Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Knhsict2019
K
Knhsict2019
Community Contributor
Quizzes Created: 1 | Total Attempts: 412
| Attempts: 412 | Questions: 38
Please wait...
Question 1 / 38
0 %
0/100
Score 0/100
1. Public class Test{ static void main(String[] args) { System.out.println("Hello World"); }} What is the correct syntax in compiling java program?  

Explanation

The correct syntax for compiling a Java program is "javac Test.java". This command is used to compile the Java source code file named "Test.java" into bytecode, which can then be executed by the Java Virtual Machine.

Submit
Please wait...
About This Quiz
Java Quizzes & Trivia

This will be the first quiz of our Programming 11 class. It will be to review basic introductory concepts covered in our Java Topics.

Tell us your name to personalize your report, certificate & get on the leaderboard!
2. Public class Test{ static void main(String[] args) { System.out.println("Hello World"); }} What is the correct syntax in compiling java program?  

Explanation

The correct syntax for compiling a Java program is "javac Test.java". This command is used to compile the Java source code file named "Test.java" into bytecode, which can then be executed by the Java Virtual Machine.

Submit
3. Your program file name is the same with___?

Explanation

The correct answer is "Class Name" because in Java, the program file name must match the name of the class that contains the main method. This is a requirement for the Java compiler to be able to identify and execute the program correctly. Therefore, the program file name should be the same as the class name to ensure proper execution.

Submit
4. Public class Test { static void main(String[] args) { System.out.println("Hello World"); } } What must be the file name of this java program?  

Explanation

The file name of a Java program must match the name of the public class in the program. In this case, the public class is named "Test", so the file name must be "Test.java".

Submit
5. Choose the appropriate data type for this value:  1

Explanation

The value 1 is a whole number and does not contain any decimal places. Therefore, the appropriate data type for this value is "int," which represents integers or whole numbers in programming.

Submit
6. Public class Test { static void main(String[] args) { System.out.println("Hello World"); } Is there any syntax error for this program?  

Explanation

The given program has a syntax error because the main method should be declared as public in order to be accessed by the Java Virtual Machine (JVM). Additionally, the closing parenthesis after "args" is missing, which is also a syntax error.

Submit
7. Choose the best definition for a Class.

Explanation

A class is an object definition that contains the necessary data and function elements required to create an object. In object-oriented programming, a class serves as a blueprint or template for creating objects. It defines the properties (data) and behaviors (functions) that an object of that class can have. By creating multiple objects from a class, we can utilize the defined properties and behaviors to perform specific actions or tasks.

Submit
8. Choose the appropriate data type for this value:  "dog"

Explanation

The value "dog" is a word or a sequence of characters, which is represented by the data type String. The String data type is used to store textual data in programming languages and is the appropriate choice for representing words, sentences, or any other combination of characters.

Submit
9. Choose the appropriate data type for this value:  5.5

Explanation

The value 5.5 is a decimal number, so the appropriate data type to represent it would be double. The double data type is used to store floating-point numbers with a higher precision than the float data type.

Submit
10. System.out.print (2+5) What is the possible out for this?

Explanation

The statement "System.out.print(2+5)" is a Java code that prints the result of the expression "2+5" to the console. Since the expression evaluates to 7, the output will be 7.

Submit
11. Import java.util.Scanner; public class MyClass { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int num = input.nextInt(); if(num % 2 == 0) System.out.print(num+" is an even number"); else System.out.print(num+" is an odd number");   } }   What would the the Possible output if the given integer is 12?  

Explanation

The possible output if the given integer is 12 would be "12 is an even number". This is because the code checks if the given number is divisible by 2 using the modulus operator (%). If the remainder is 0, it means the number is even, so the program prints "is an even number" along with the given number. In this case, since 12 is divisible by 2 without any remainder, the output would indicate that it is an even number.

Submit
12. Choose the best definition of an object

Explanation

An object is best defined as an instance of a class. In object-oriented programming, a class is a blueprint or template that defines the properties and behaviors of objects. An object, on the other hand, is a specific instance created from that class, with its own unique set of values for the class's properties. Therefore, an object is not just any thing or something you wear, but specifically an instance of a class.

Submit
13. public class Example2 { public static void main ( String[] args ) {int hoursWorked = 40; double payRate = 10.0; System.out.println("Hours Worked: " + hoursWorked ); System.out.println("pay Amount : "+ (hoursWorked*payRate));   } } What is the possible output of this program?

Explanation

The possible output of this program is "Hours Worked: 40" and "pay Amount : 400". This is because the program initializes the variable "hoursWorked" with a value of 40 and the variable "payRate" with a value of 10.0. It then calculates the pay amount by multiplying the hours worked by the pay rate and prints it out using the System.out.println() method. In this case, the calculation would be 40 * 10.0 = 400, resulting in the output "pay Amount : 400".

Submit
14. Which of the following always need a Capital letter ?

Explanation

Class names and Strings always need a capital letter because it is a common convention in programming languages to use capital letters to distinguish between different types of identifiers. Class names typically start with a capital letter to make them easily recognizable and distinguishable from variables and methods. Similarly, Strings are often written with a capital letter at the beginning to indicate that they are a specific type of data.

Submit
15. Choose the appropriate data type for this value:  true

Explanation

true/false = boolean (only two possible answers)

Submit
16. Import java.util.Scanner; public class MyClass { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int num = input.nextInt(); if(num % 2 == 0) System.out.print(num+" is an even number"); else System.out.print(num+" is an odd number");   } }   What data types declared in this program?  

Explanation

The data type declared in this program is integer. This is because the variable "num" is declared as an int and is used to store the user input, which is expected to be an integer.

Submit
17. Int a=5, b=10, sum; sum=a+b System.out.print("The sum of two integers is:" ____) What is the correct java syntax for this:  

Explanation

The correct Java syntax for printing the sum of two integers is "+sum". This is because the variable "sum" holds the value of the addition operation between variables "a" and "b", and the "+" symbol is used to concatenate the string "The sum of two integers is:" with the value of "sum" when printing it.

Submit
18.
  1. class mainclass {
  2.         public static void main(String args[]) 
  3.         {
  4.             boolean var1 = true;
  5. 	    boolean var2 = false;
  6. 	    if (var1)
  7. 	        System.out.println(var1);
  8. 	    else
  9. 	        System.out.println(var2);
  10.        } 
  11.     }

Explanation

The code declares two boolean variables, var1 and var2, with values true and false respectively. The if statement checks if var1 is true, and since it is, it prints out the value of var1, which is true. Therefore, the correct answer is true.

Submit
19. Choose the appropriate data type for this value:  true

Explanation

The correct answer is boolean because the value "true" is a boolean value, representing either true or false. The boolean data type is used to store and manipulate boolean values in programming languages.

Submit
20. Choose the appropriate data type for this field:  numberOfEggs

Explanation

The appropriate data type for the field "numberOfEggs" is int because it suggests that the field will store a whole number value representing the count of eggs. The int data type is used for storing integers, which are whole numbers without any decimal places.

Submit
21. Choose the appropriate data type for this field:   kindOfBird

Explanation

example: kindOfBird = "Parrot"

Submit
22. A data types that holds decimal numbers:

Explanation

The data type "double" is used to hold decimal numbers in programming. It allows for the storage of both whole numbers and numbers with decimal points. This data type is commonly used in situations where precision is required, such as in financial calculations or scientific computations. Unlike integer data types, which can only store whole numbers, the double data type can represent a wider range of values, including fractions and very large or very small numbers. Therefore, "double" is the correct answer for a data type that holds decimal numbers.

Submit
23. An old name for Java Programming

Explanation

Oak was the original name for the programming language that eventually became Java. It was developed by James Gosling and his team at Sun Microsystems in the early 1990s. However, due to trademark issues, the name was changed to Java. Oak was designed to be a platform-independent language for programming consumer electronics devices, but it was later adapted and rebranded as Java for broader use in web and application development.

Submit
24. Choose the appropriate data type for this field: eggColour

Explanation

The field "eggColour" suggests that it is referring to the color of an egg. Since egg colors can vary and are not limited to a specific set of options, a String data type would be appropriate. String data type allows for storing a sequence of characters, which can accommodate different egg colors as text.

Submit
25. What is the error in this following java program:   public class Employee { public showName () { name = Walter; System.out.println ("Employee's name is: " + name); } }

Explanation

The error in this Java program is that no data type is declared for the method "showName()". In Java, every method should have a return type specified, even if it is void. Therefore, the correct way to declare the method would be "public void showName()".

Submit
26.
  1. class area {
  2.         public static void main(String args[]) 
  3.         {    
  4.              double r, pi, a;
  5.              r = 9.8;
  6.              pi = 3.14;
  7.              a = pi * r * r;
  8.              System.out.println(a);
  9.         } 
  10.     }

Explanation

The given code calculates the area of a circle using the formula A = πr^2. The variables r and pi are initialized with values 9.8 and 3.14 respectively. The area is then calculated by multiplying pi, r, and r together. The result is printed to the console, which in this case is 301.5656.

Submit
27. Import java.util.Scanner; public class MyClass { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int num = input.nextInt(); if(num % 2 == 0) System.out.print(num+" is an even number"); else System.out.print(num+" is an odd number");   } }   What syntax that display the integer inputted by the user?  

Explanation

The syntax "System.out.print("Enter an integer: ");" is used to display the prompt message asking the user to enter an integer.

Submit
28. Import java.util.Scanner; public class MyClass { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int num = input.nextInt(); if(num % 2 == 0) System.out.print(num+" is an even number"); else System.out.print(num+" is an odd number");   } }   What syntax determine the conditional statement?  

Explanation

The syntax that determines the conditional statement is "if(num % 2 == 0)". This statement checks if the remainder of the division of the variable "num" by 2 is equal to 0. If it is, then the number is even.

Submit
29. Choose the appropriate data type for this field:  weightInKilos

Explanation

The appropriate data type for the field "weightInKilos" would be double. This is because weight is typically represented as a decimal number and the double data type can accommodate decimal values with a larger range than the float data type. Using a double data type allows for more precise calculations and storage of weight values in kilograms.

Submit
30. What is .java

Explanation

The correct answer is "An extension file." In Java programming, the .java extension is used to identify source code files written in the Java programming language. These files contain the code that is written by developers and are later compiled into executable files with the .class extension. The .java extension is not an executable file itself, but rather indicates that the file contains Java source code.

Submit
31.  What is the output of this program?
  1.     class increment {
  2.         public static void main(String args[]) 
  3.         {        
  4.              int g = 3;
  5.              System.out.print(++g * 8);
  6.         } 
  7.     }

Explanation

The program declares a variable "g" and assigns it the value 3. The expression "++g" increments the value of "g" by 1 before the multiplication. So, "++g * 8" is equivalent to "4 * 8", which results in 32.

Submit
32. Import java.util.Scanner; public class MyClass { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int num = input.nextInt(); if(num % 2 == 0) System.out.print(num+" is an even number"); else System.out.print(num+" is an odd number");   } }   What syntax determine the number to be inputted by the user?  

Explanation

The syntax "int num = input.nextInt();" determines the number to be inputted by the user. It uses the Scanner class to create an object called "input" that reads input from the user. The "nextInt()" method is then used to read the next integer entered by the user and assign it to the variable "num". This allows the program to use the user's input for further calculations or processing.

Submit
33. Choose the appropriate data type for this field: isSwimmer

Explanation

isSwimmer - yes or no (only two possible answers = boolean)

Submit
34. Choose the appropriate data type for this value:  "x1"

Explanation

String's always have " " around them!

Submit
35. Choose the appropriate data type for this value:  A

Explanation

The appropriate data type for the value "A" would be char. The value "A" is a single character, so it can be stored as a char data type.

Submit
36.
  1.  class dynamic_initialization 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             double a, b;
  6.             a = 3.0;
  7.             b = 4.0;
  8. 	    double c = Math.sqrt(a * a + b * b);
  9. 	    System.out.println(c);
  10.         } 
  11.     }

Explanation

The code initializes two variables, "a" and "b", with the values 3.0 and 4.0 respectively. It then calculates the value of "c" using the formula Math.sqrt(a * a + b * b), which computes the square root of the sum of the squares of "a" and "b". In this case, the value of "c" is 5.0. Finally, the code prints the value of "c" to the console.

Submit
37.
  1.  class dynamic_initialization 
  2.     {
  3.         public static void main(String args[]) 
  4.         {
  5.             double a, b;
  6.             a = 3.0;
  7.             b = 4.0;
  8. 	    double c = Math.sqrt(a * a + b * b);
  9. 	    System.out.println(c);
  10.         } 
  11.     }

Explanation

The program calculates the value of c using the Pythagorean theorem, which states that in a right triangle, the square of the length of the hypotenuse (c) is equal to the sum of the squares of the other two sides (a and b). In this case, a is 3.0 and b is 4.0. The program then uses the Math.sqrt() function to find the square root of the sum of a^2 and b^2, which is 5.0. Therefore, the correct answer is 5.0.

Submit
38. Write the following Java Program that will display this output: Look for the class name on the image display: Look for the output that will display on your program:

Explanation

The given answer is correct because it includes the correct class name "KNHS" and the correct main method signature "public static void main(String[] args)". It also includes the correct statement to display the output "System.out.println("I am a Student of Kalayaan National High School");". Therefore, when this program is executed, it will display the desired output.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jul 20, 2019
    Quiz Created by
    Knhsict2019
Cancel
  • All
    All (38)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Public class Test{ ...
Public class Test{...
Your program file name is the same with___?
Public class Test { ...
Choose the appropriate data type for this value:  1
Public class Test { ...
Choose the best definition for a Class.
Choose the appropriate data type for this value:  "dog"
Choose the appropriate data type for this value:  5.5
System.out.print (2+5) What is the possible out for this?
Import java.util.Scanner; ...
Choose the best definition of an object
Public class Example2 ...
Which of the following always need a Capital letter ?
Choose the appropriate data type for this value:  true
Import java.util.Scanner; ...
Int a=5, b=10, sum;...
Class mainclass { ...
Choose the appropriate data type for this value:  true
Choose the appropriate data type for this field:  numberOfEggs
Choose the appropriate data type for this field:  ...
A data types that holds decimal numbers:
An old name for Java Programming
Choose the appropriate data type for this field: eggColour
What is the error in this following java program: ...
Class area { ...
Import java.util.Scanner; ...
Import java.util.Scanner; ...
Choose the appropriate data type for this field:  weightInKilos
What is .java
 What is the output of this program? ...
Import java.util.Scanner; ...
Choose the appropriate data type for this field: isSwimmer
Choose the appropriate data type for this value:  "x1"
Choose the appropriate data type for this value:  A
Class dynamic_initialization ...
Class dynamic_initialization ...
Write the following Java Program that will display this output: ...
Alert!

Advertisement