Java Basics (easy)
60 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following is a primitive datatype in Java?

  • object
  • string
  • integer (correct)
  • class

Which operator is used for incrementing the value of a variable by 1 in Java?

  • *
  • +
  • ++ (correct)
  • -

Which operator is used for performing arithmetic operations in Java?

  • =
  • &&
  • + (correct)
  • ||

What does the following code snippet do?

int x = 5; x += 3;

<p>Assigns the value 8 to x (C)</p> Signup and view all the answers

Which of the following is a conditional statement in Java?

<p>if (C)</p> Signup and view all the answers

What is the purpose of the logical operator && in Java?

<p>Perform logical AND operation (B)</p> Signup and view all the answers

Which of the following is NOT an access specifier in Java?

<p>package (A)</p> Signup and view all the answers

What is the return type of a method that does not return any value?

<p>void (C)</p> Signup and view all the answers

What is the purpose of arguments/parameters in a method?

<p>To pass values to the method for processing (B)</p> Signup and view all the answers

What is the difference between function declaration and function definition in Java?

<p>Function declaration is the prototype of the function, while function definition contains the body of the function (B)</p> Signup and view all the answers

What happens when a method is called in Java?

<p>The program starts searching for the function definition (B)</p> Signup and view all the answers

What is method overloading in Java?

<p>Defining multiple methods with the same name and different arguments (A)</p> Signup and view all the answers

Which of the following is an alternative to if...else statement in Java?

<p>Switch case (B)</p> Signup and view all the answers

What is the purpose of the 'break' statement in switch case?

<p>To terminate a specific iteration of a loop (A)</p> Signup and view all the answers

Which type of loop in Java is entry-controlled?

<p>For loop (B)</p> Signup and view all the answers

What is the syntax for a method in Java?

<p>Access_specifier return_type method_name (arguments) { Body of the method; } (B)</p> Signup and view all the answers

What is the purpose of the 'continue' statement in a loop?

<p>To terminate a specific iteration of a loop (C)</p> Signup and view all the answers

Which type of loop in Java is exit-controlled?

<p>Do...while loop (B)</p> Signup and view all the answers

Which one of the following is an example of a class in Java?

<p>Car (C)</p> Signup and view all the answers

Which one of the following is an example of an object in Java?

<p>Car (D)</p> Signup and view all the answers

What is the syntax for defining a class in Java?

<p>access_specifier class className { Class definition containing variables and methods; } (C)</p> Signup and view all the answers

What is an object in Java?

<p>An instance of a class (C)</p> Signup and view all the answers

What are comments used for in Java?

<p>To increase the understanding and readability of the program (D)</p> Signup and view all the answers

What are the rules for writing a Java program?

<p>Java uses higher CamelCase for writing class names and lower camelCase for writing method names (C)</p> Signup and view all the answers

Which keyword is used to declare the main method in a Java program?

<p>static (B)</p> Signup and view all the answers

What is the purpose of the 'System.out.print()' method in Java?

<p>To display something on the screen during program execution (A)</p> Signup and view all the answers

What is the purpose of the 'println()' method in Java?

<p>To move the cursor to the next line after printing (D)</p> Signup and view all the answers

What is the role of the 'String args[]' in the main method of a Java program?

<p>It is an array of strings that stores arguments passed by the command line (B)</p> Signup and view all the answers

Why does the main method in a Java program have to be declared static?

<p>To allow main() to be called without creating an object of the class (A)</p> Signup and view all the answers

What is the purpose of the 'public' keyword in Java?

<p>To specify the visibility of a class or method (A)</p> Signup and view all the answers

Which of the following is a bitwise operator in Java?

<p>&amp; (D)</p> Signup and view all the answers

What is the result of the expression 'x += 5' in Java?

<p>x + 5 (B)</p> Signup and view all the answers

Which type of loop in Java is exit-controlled?

<p>do-while loop (B)</p> Signup and view all the answers

What is the purpose of the '==' operator in Java?

<p>Comparison (B)</p> Signup and view all the answers

Which of the following is NOT a primitive datatype in Java?

<p>String (B)</p> Signup and view all the answers

What is the purpose of the 'else if' statement in Java?

<p>To check multiple conditions (A)</p> Signup and view all the answers

Which keyword is used to declare the main method in a Java program?

<p>main (B)</p> Signup and view all the answers

What is the purpose of the 'public' keyword in Java?

<p>To specify the access level of a class, method, or variable (A)</p> Signup and view all the answers

What is the purpose of the 'continue' statement in a loop?

<p>To skip the current iteration and move to the next iteration (A)</p> Signup and view all the answers

Which type of loop in Java is exit-controlled?

<p>Do-while loop (C)</p> Signup and view all the answers

What is the purpose of the logical operator && in Java?

<p>To perform logical AND operation (D)</p> Signup and view all the answers

What are comments used for in Java?

<p>To explain the functionality of the code (A)</p> Signup and view all the answers

Which keyword is used to declare a method in Java?

<p>public (C)</p> Signup and view all the answers

What is the return type of a method that does not return any value?

<p>void (B)</p> Signup and view all the answers

What is the purpose of arguments/parameters in a method?

<p>To pass values to the method (D)</p> Signup and view all the answers

What is the purpose of the 'println()' method in Java?

<p>To print the value of a variable (D)</p> Signup and view all the answers

What is method overloading in Java?

<p>Defining multiple methods with the same name but different arguments (C)</p> Signup and view all the answers

What is the purpose of the 'continue' statement in a loop?

<p>To skip the current iteration of the loop and move to the next iteration (C)</p> Signup and view all the answers

Which type of loop in Java is exit-controlled?

<p>Do...while loop (A)</p> Signup and view all the answers

What is the purpose of the 'continue' statement in Java?

<p>To terminate a particular iteration of a loop (D)</p> Signup and view all the answers

What is the purpose of the 'break' statement in Java?

<p>To terminate the entire loop and come out of it (B)</p> Signup and view all the answers

What is the purpose of methods in Java?

<p>To make the program modular and simpler (B)</p> Signup and view all the answers

What is the syntax for a method in Java?

<p>Access_specifier return_type method_name (arguments) { Body of the method; } (C)</p> Signup and view all the answers

Which type of loop in Java is entry-controlled?

<p>For loop (D)</p> Signup and view all the answers

Which one of these is a correct statement about classes and objects in Java?

<p>A class is a blueprint or template for creating objects. (D)</p> Signup and view all the answers

What is the purpose of comments in Java?

<p>To increase the understanding and readability of the program. (D)</p> Signup and view all the answers

Which of the following is a rule for writing a Java program?

<p>Variable names should start with an alphabet or an underscore (_). (D)</p> Signup and view all the answers

What is the role of the 'String args[]' in the main method of a Java program?

<p>It is used to pass command-line arguments to the program. (B)</p> Signup and view all the answers

What is the purpose of the 'public' keyword in Java?

<p>It is an access specifier that allows the method to be accessed from anywhere. (A)</p> Signup and view all the answers

What is an alternative to the if...else statement in Java?

<p>The switch statement. (A)</p> Signup and view all the answers
Use Quizgecko on...
Browser
Browser