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</p> Signup and view all the answers

    Which of the following is a conditional statement in Java?

    <p>if</p> Signup and view all the answers

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

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

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

    <p>package</p> Signup and view all the answers

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

    <p>void</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</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</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</p> Signup and view all the answers

    What is method overloading in Java?

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

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

    <p>Switch case</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</p> Signup and view all the answers

    Which type of loop in Java is entry-controlled?

    <p>For loop</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; }</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</p> Signup and view all the answers

    Which type of loop in Java is exit-controlled?

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

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

    <p>Car</p> Signup and view all the answers

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

    <p>Car</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; }</p> Signup and view all the answers

    What is an object in Java?

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

    What are comments used for in Java?

    <p>To increase the understanding and readability of the program</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</p> Signup and view all the answers

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

    <p>static</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</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</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</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</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</p> Signup and view all the answers

    Which of the following is a bitwise operator in Java?

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

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

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

    Which type of loop in Java is exit-controlled?

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

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

    <p>Comparison</p> Signup and view all the answers

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

    <p>String</p> Signup and view all the answers

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

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

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

    <p>main</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</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</p> Signup and view all the answers

    Which type of loop in Java is exit-controlled?

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

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

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

    What are comments used for in Java?

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

    Which keyword is used to declare a method in Java?

    <p>public</p> Signup and view all the answers

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

    <p>void</p> Signup and view all the answers

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

    <p>To pass values to the method</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</p> Signup and view all the answers

    What is method overloading in Java?

    <p>Defining multiple methods with the same name but different arguments</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</p> Signup and view all the answers

    Which type of loop in Java is exit-controlled?

    <p>Do...while loop</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</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</p> Signup and view all the answers

    What is the purpose of methods in Java?

    <p>To make the program modular and simpler</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; }</p> Signup and view all the answers

    Which type of loop in Java is entry-controlled?

    <p>For loop</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.</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.</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 (_).</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.</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.</p> Signup and view all the answers

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

    <p>The switch statement.</p> Signup and view all the answers

    More Like This

    Use Quizgecko on...
    Browser
    Browser