Programming 11: Java Assesement Exam

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Knhsict2019
K
Knhsict2019
Community Contributor
Quizzes Created: 1 | Total Attempts: 409
Questions: 38 | Attempts: 409

SettingsSettingsSettings
Programming 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.


Questions and Answers
  • 1. 

    Choose the best definition for a Class.

    • A.

      A group of students in a room

    • B.

      An object definition, containing the data and function elements necessary to create an object

    • C.

      An action for a program

    Correct Answer
    B. An object definition, containing the data and function elements necessary to create an object
    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.

    Rate this question:

  • 2. 

    Choose the best definition of an object

    • A.

      A thing

    • B.

      An instance of a class

    • C.

      Something you wear

    Correct Answer
    B. An instance of a class
    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.

    Rate this question:

  • 3. 

    Choose the appropriate data type for this value:  "dog"

    • A.

      Int

    • B.

      String

    • C.

      Double

    • D.

      Boolean

    Correct Answer
    B. String
    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.

    Rate this question:

  • 4. 

    Choose the appropriate data type for this value:  true

    • A.

      Int

    • B.

      Double

    • C.

      String

    • D.

      Boolean

    Correct Answer
    D. Boolean
    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.

    Rate this question:

  • 5. 

    Choose the appropriate data type for this value:  1

    • A.

      Int

    • B.

      Double

    • C.

      String

    • D.

      Boolean

    Correct Answer
    A. Int
    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.

    Rate this question:

  • 6. 

    Choose the appropriate data type for this value:  5.5

    • A.

      Int

    • B.

      Double

    • C.

      Boolean

    • D.

      String

    Correct Answer
    B. Double
    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.

    Rate this question:

  • 7. 

    Choose the appropriate data type for this value:  A

    • A.

      Int

    • B.

      Double

    • C.

      Char

    • D.

      String

    Correct Answer
    C. Char
    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.

    Rate this question:

  • 8. 

    Choose the appropriate data type for this value:  "x1"

    • A.

      String

    • B.

      Boolean

    • C.

      Int

    • D.

      Char

    Correct Answer
    A. String
    Explanation
    String's always have " " around them!

    Rate this question:

  • 9. 

    Choose the appropriate data type for this value:  true

    • A.

      Boolean

    • B.

      Int

    • C.

      Char

    • D.

      Double

    Correct Answer
    A. Boolean
    Explanation
    true/false = boolean (only two possible answers)

    Rate this question:

  • 10. 

    Choose the appropriate data type for this field:   kindOfBird

    • A.

      String

    • B.

      Int

    • C.

      Char

    • D.

      Double

    Correct Answer
    A. String
    Explanation
    example: kindOfBird = "Parrot"

    Rate this question:

  • 11. 

    Choose the appropriate data type for this field:  numberOfEggs

    • A.

      Double

    • B.

      Char

    • C.

      Boolean

    • D.

      Int

    Correct Answer
    D. Int
    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.

    Rate this question:

  • 12. 

    Choose the appropriate data type for this field:  weightInKilos

    • A.

      Char

    • B.

      String

    • C.

      Double

    • D.

      Boolean

    Correct Answer
    C. Double
    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.

    Rate this question:

  • 13. 

    Choose the appropriate data type for this field: isSwimmer

    • A.

      Double

    • B.

      Boolean

    • C.

      String

    • D.

      Int

    Correct Answer
    B. Boolean
    Explanation
    isSwimmer - yes or no (only two possible answers = boolean)

    Rate this question:

  • 14. 

    Choose the appropriate data type for this field: eggColour

    • A.

      Boolean

    • B.

      Char

    • C.

      Int

    • D.

      String

    Correct Answer
    D. String
    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.

    Rate this question:

  • 15. 

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

    • A.

      7

    • B.

      2+5

    • C.

      (2+5)

    • D.

      0

    Correct Answer
    A. 7
    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.

    Rate this question:

  • 16. 

    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:  

    • A.

      A+b=sum

    • B.

      +sum

    • C.

      15

    • D.

      A+b

    Correct Answer
    B. +sum
    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.

    Rate this question:

  • 17. 

    An old name for Java Programming

    • A.

      Sun Microsystem

    • B.

      Javac

    • C.

      Lava

    • D.

      Oak

    Correct Answer
    D. Oak
    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.

    Rate this question:

  • 18. 

    Which of the following always need a Capital letter ?

    • A.

      Class names and Strings

    • B.

      Objects and class names

    • C.

      Fields and Strings

    • D.

      Data types and fields

    Correct Answer
    A. Class names and Strings
    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.

    Rate this question:

  • 19. 

    A data types that holds decimal numbers:

    • A.

      Double

    • B.

      Integers

    • C.

      Boolean

    • D.

      String

    Correct Answer
    A. Double
    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.

    Rate this question:

  • 20. 

    Your program file name is the same with___?

    • A.

      Output

    • B.

      Class Name

    • C.

      Main String

    • D.

      Syntax

    Correct Answer
    B. Class Name
    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.

    Rate this question:

  • 21. 

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

    • A.

      Test.java

    • B.

      Test.java

    • C.

      Test.javac

    • D.

      Test.javax

    Correct Answer
    B. Test.java
    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".

    Rate this question:

  • 22. 

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

    • A.

      Yes, there is a Syntax error

    • B.

      No

    • C.

      Prrom will dispaly its output

    • D.

      Maybe

    Correct Answer
    A. Yes, there is a Syntax error
    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.

    Rate this question:

  • 23. 

    Public class Test{ static void main(String[] args) { System.out.println("Hello World"); }} What is the correct syntax in compiling java program?  

    • A.

      Java.Test javac

    • B.

      Test.java.javac

    • C.

      Javac Test.java

    • D.

      Test.java

    Correct Answer
    C. Javac Test.java
    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.

    Rate this question:

  • 24. 

    Public class Test{ static void main(String[] args) { System.out.println("Hello World"); }} What is the correct syntax in compiling java program?  

    • A.

      Java.Test javac

    • B.

      Test.java.javac

    • C.

      Javac Test.java

    • D.

      Test.java

    Correct Answer
    C. Javac Test.java
    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.

    Rate this question:

  • 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); } }

    • A.

      No data type declared

    • B.

      Wrong format

    • C.

      No variable name

    • D.

      No Object type

    Correct Answer
    A. No data type declared
    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()".

    Rate this question:

  • 26. 

    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?

    • A.

      Hours Worked:40 pay Amount :10  

    • B.

      Hours Worked:40 pay Amount :400  

    • C.

      Hours Worked:40 pay Amount :100  

    • D.

      Hours Worked:400 pay Amount :  

    Correct Answer
    B. Hours Worked:40 pay Amount :400  
    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".

    Rate this question:

  • 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 would the the Possible output if the given integer is 12?

    • A.

      12 is an even number

    • B.

      A number is even number

    • C.

      12 is an integer

    • D.

      Num 12 is an even number

    Correct Answer
    A. 12 is an even number
    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.

    Rate this question:

  • 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 number to be inputted by the user?

    • A.

      Scanner input = new Scanner(System.in);

    • B.

      System.out.print("Enter an integer: ");

    • C.

      Int num = input.nextInt();

    • D.

      If(num % 2 == 0)

    Correct Answer
    C. Int num = input.nextInt();
    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.

    Rate this question:

  • 29. 

    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?

    • A.

      Scanner input = new Scanner(System.in);

    • B.

      System.out.print("Enter an integer: ");

    • C.

      Int num = input.nextInt();

    • D.

      If(num % 2 == 0)

    Correct Answer
    D. If(num % 2 == 0)
    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.

    Rate this question:

  • 30. 

    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?

    • A.

      Scanner input = new Scanner(System.in);

    • B.

      System.out.print("Enter an integer: ");

    • C.

      Int num = input.nextInt();

    • D.

      If(num % 2 == 0)

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

    Rate this question:

  • 31. 

    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?

    • A.

      String

    • B.

      Integer

    • C.

      Boolean

    • D.

      Double

    Correct Answer
    B. Integer
    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.

    Rate this question:

  • 32. 

    What is .java

    • A.

      A filename

    • B.

      A executable file

    • C.

      An extension file

    • D.

      An Object

    Correct Answer
    C. An extension file
    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.

    Rate this question:

  • 33. 

     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. }

    • A.

      25

    • B.

      24

    • C.

      32

    • D.

      33

    Correct Answer
    C. 32
    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.

    Rate this question:

  • 34. 

    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. }

    • A.

      301.5656

    • B.

      301

    • C.

      301.56

    • D.

      301.00111

    Correct Answer
    A. 301.5656
    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.

    Rate this question:

  • 35. 

    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. }

    • A.

      1

    • B.

      False

    • C.

      True

    • D.

      0

    Correct Answer
    C. True
    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.

    Rate this question:

  • 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. }

    • A.

      1

    • B.

      5.0

    • C.

      7.0

    • D.

      Compilation error!

    Correct Answer
    B. 5.0
    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.

    Rate this question:

  • 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. }

    • A.

      1

    • B.

      5.0

    • C.

      7.0

    • D.

      Compilation error!

    Correct Answer
    B. 5.0
    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.

    Rate this question:

  • 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:

    Correct Answer
    class KNHS { public static void main(String[] args) { System.out.println("I am a Student of Kalayaan National High School"); } }
    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.

    Rate this question:

Quiz Review Timeline +

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.