Quiz No. 2 In Java Programming

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 Ricador
R
Ricador
Community Contributor
Quizzes Created: 14 | Total Attempts: 54,779
Questions: 30 | Attempts: 2,162

SettingsSettingsSettings
Quiz No. 2 In Java Programming - Quiz

The quiz is about identification of the correct or incorrect declaration of identifiers and Java statements. (Valid or Invalid / Correct or Incorrect)


Questions and Answers
  • 1. 

    Select V if the identifier below is VALID, otherwise select I.      ==counter

    • A.

      V

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The identifier "==counter" is not valid because it starts with a double equals sign, which is not allowed in most programming languages. Identifiers should typically start with a letter or an underscore, followed by letters, numbers, or underscores.

    Rate this question:

  • 2. 

    Select V if the identifier below is VALID, otherwise select I.      initial

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "initial" is valid because it follows the rules for naming identifiers in most programming languages. It starts with a letter and can be followed by letters, numbers, or underscores.

    Rate this question:

  • 3. 

    Select V if the identifier below is VALID, otherwise select I.      2nd_num

    • A.

      V

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The identifier "2nd_num" is not valid because it starts with a number, which is not allowed in most programming languages. Identifiers typically need to start with a letter or an underscore.

    Rate this question:

  • 4. 

    Select V if the identifier below is VALID, otherwise select I.      *pointer

    • A.

      V

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The identifier "*pointer" is not valid because it starts with an asterisk symbol (*), which is not allowed in variable names. Variable names in most programming languages can only contain letters, numbers, and underscores, and must start with a letter or an underscore.

    Rate this question:

  • 5. 

    Select V if the identifier below is VALID, otherwise select I.      Main

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "Main" is valid because it starts with a capital letter and does not contain any special characters or spaces. In programming, identifiers are used to name variables, functions, or other entities, and they must follow certain rules and conventions. In this case, "Main" follows the convention of using a capital letter for the start of the identifier, making it a valid choice.

    Rate this question:

  • 6. 

    Select V if the identifier below is VALID, otherwise select I.      _Public

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "_Public" is valid because it starts with an underscore, which is a valid character for identifiers in many programming languages.

    Rate this question:

  • 7. 

    Select V if the identifier below is VALID, otherwise select I.      Strong

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "Strong" is valid because it follows the rules for naming identifiers. In most programming languages, identifiers can consist of letters, numbers, and underscores, and can start with a letter or an underscore. Since "Strong" consists only of letters and starts with a capital letter, it is considered a valid identifier.

    Rate this question:

  • 8. 

    Select V if the identifier below is VALID, otherwise select I.      cake

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "cake" is valid because it follows the rules for naming identifiers. It starts with a letter, does not contain any special characters or spaces, and is not a reserved keyword. Therefore, it can be used as a valid identifier in a programming language.

    Rate this question:

  • 9. 

    Select V if the identifier below is VALID, otherwise select I.      int

    • A.

      V

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given identifier "int" is not valid because it is a reserved keyword in many programming languages, including C++, Java, and C#. Reserved keywords cannot be used as identifiers in the code.

    Rate this question:

  • 10. 

    Select V if the identifier below is VALID, otherwise select I.      Default

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "Default" is valid because it follows the rules for naming identifiers. In most programming languages, identifiers can consist of letters, numbers, and underscores, and can start with a letter or an underscore. Since "Default" only contains letters and starts with a capital letter, it is a valid identifier.

    Rate this question:

  • 11. 

    Select V if the identifier below is VALID, otherwise select I.      char

    • A.

      V

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The identifier "char" is not a valid identifier because it is a reserved keyword in many programming languages, including C, C++, and Java. Reserved keywords have a predefined meaning in the language and cannot be used as identifiers for variables, functions, or other entities in the code. Therefore, "char" cannot be used as a valid identifier.

    Rate this question:

  • 12. 

    Select V if the identifier below is VALID, otherwise select I.      b

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "b" is a valid identifier because it consists of a single letter. In programming, identifiers are used to name variables, functions, or other entities, and they must follow certain rules. In this case, the identifier "b" meets the requirement of being a valid identifier as it is a single letter.

    Rate this question:

  • 13. 

    Select V if the identifier below is VALID, otherwise select I.      Byte

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "Byte" is valid because it starts with a capital letter, which is allowed in most programming languages. It also consists of only letters, which is another valid character for an identifier. Therefore, "Byte" meets the criteria for a valid identifier.

    Rate this question:

  • 14. 

    Select V if the identifier below is VALID, otherwise select I.      short

    • A.

      V

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The identifier "short" is not valid because it is a reserved keyword in many programming languages, including C and C++. Reserved keywords cannot be used as identifiers because they have special meanings in the language.

    Rate this question:

  • 15. 

    Select V if the identifier below is VALID, otherwise select I.      large

    • A.

      V

    • B.

      I

    Correct Answer
    A. V
    Explanation
    The identifier "large" is a valid identifier because it starts with a letter and does not contain any special characters or spaces. It follows the rules for naming identifiers in programming languages.

    Rate this question:

  • 16. 

    Select C if the given statement is CORRECT, otherwise select I.      Boolean a;

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement "Boolean a;" is incorrect because it is missing the variable declaration and initialization. In Java, when declaring a variable, we need to specify its type and give it a name. Additionally, we should also assign a value to the variable. Therefore, the correct statement should be something like "boolean a = false;" where "boolean" is the type, "a" is the variable name, and "false" is the initial value.

    Rate this question:

  • 17. 

    Select C if the given statement is CORRECT, otherwise select I.      System.out.println('Welcome to Java');

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because the println() method in Java requires a string argument to be passed inside the parentheses. In this case, 'Welcome to Java' is not enclosed in double quotes, which makes it a character literal instead of a string literal. To make the statement correct, it should be written as System.out.println("Welcome to Java");

    Rate this question:

  • 18. 

    Select C if the given statement is CORRECT, otherwise select I.      double 56;

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement "double 56" is incorrect. In programming, "double" is a data type used to store decimal numbers with double precision. However, in this statement, "double" is being used as a variable name, which is not allowed. Variable names cannot start with a number, and "56" is not a valid variable name. Therefore, the statement is incorrect.

    Rate this question:

  • 19. 

    Select C if the given statement is CORRECT, otherwise select I.      char next_line="\n");

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because it contains syntax errors. The variable "next_line" is assigned with a value that is not a valid character. The correct way to assign a new line character to a char variable is by using '\n' instead of "".

    Rate this question:

  • 20. 

    Select C if the given statement is CORRECT, otherwise select I.      Public class SECOND {

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because the correct way to declare a public class in Java is by using the keyword "public" followed by the class name. In this case, the class name is "SECOND". Therefore, the correct statement should be "public class SECOND".

    Rate this question:

  • 21. 

    Select C if the given statement is CORRECT, otherwise select I.      public static void main (string [] args) {

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because the "string" keyword should be capitalized as "String" in Java.

    Rate this question:

  • 22. 

    Select C if the given statement is CORRECT, otherwise select I.      float a, int b;

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because it is not possible to declare a float variable and an int variable in the same line without specifying the variable names.

    Rate this question:

  • 23. 

    Select C if the given statement is CORRECT, otherwise select I.      System.out.pritnln("Java Programming is COOL!");

    • A.

      C

    • B.

      I

    Correct Answer
    A. C
    Explanation
    The given statement is correct because it is using the correct syntax to print the string "Java Programming is COOL!" using the System.out.println() method in Java.

    Rate this question:

  • 24. 

    Select C if the given statement is CORRECT, otherwise select I.      int

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement "int" is not a complete statement and does not provide any information or context. Therefore, it is incorrect to say that the statement is correct.

    Rate this question:

  • 25. 

    Select C if the given statement is CORRECT, otherwise select I.      char gender="m";

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because the variable "gender" is assigned the value "m" without being declared as a char data type.

    Rate this question:

  • 26. 

    Select C if the given statement is CORRECT, otherwise select I.      /* This is a single line comment

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect. The correct syntax for a single line comment in most programming languages is "//" or "#" depending on the language. The statement provided, "/* This is a single line comment", is actually a multi-line comment syntax in some programming languages like C or C++.

    Rate this question:

  • 27. 

    Select C if the given statement is CORRECT, otherwise select I.      System.in.print('number');

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because the correct syntax to print something to the console in Java is System.out.print(), not System.in.print(). System.in is used for input from the user, while System.out is used for output to the console.

    Rate this question:

  • 28. 

    Select C if the given statement is CORRECT, otherwise select I.      Short classes=19;

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because in most programming languages, the syntax for declaring a variable and assigning a value to it is "data type variableName = value;" rather than "variableName = value;". Therefore, the correct answer is I.

    Rate this question:

  • 29. 

    Select C if the given statement is CORRECT, otherwise select I.      public static main void (String args[]){

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because the "main" method in Java should have a return type of "void" and the correct syntax for the main method is "public static void main(String[] args)".

    Rate this question:

  • 30. 

    Select C if the given statement is CORRECT, otherwise select I.      int number1=23.45;

    • A.

      C

    • B.

      I

    Correct Answer
    B. I
    Explanation
    The given statement is incorrect because the variable "number1" is declared as an integer, but it is assigned a decimal value (23.45). In Java, integers can only hold whole numbers, so the correct data type for the given value would be double or float.

    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
  • Nov 24, 2010
    Quiz Created by
    Ricador
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.