Java Basics (hard)
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 keyword is used to declare a method in Java?

  • class
  • public
  • static (correct)
  • void
  • What is the purpose of the 'main' method in a Java program?

  • To display output on the screen
  • To read input from the user
  • To start the execution of the program (correct)
  • To initialize variables
  • What is the purpose of the 'println' method in Java?

  • To perform mathematical calculations
  • To display output on the screen (correct)
  • To declare variables
  • To read input from the user
  • What is the purpose of the 'args' parameter in the 'main' method?

    <p>To store the arguments passed by the command line</p> Signup and view all the answers

    Which statement is true about the name of the Java file?

    <p>It should be the same as the class name</p> Signup and view all the answers

    Why does the 'main' method in a Java program have to be declared as 'public'?

    <p>To make it accessible from other classes</p> Signup and view all the answers

    Which of the following is a primitive datatype in Java?

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

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

    <p>++</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 purpose of a conditional statement in Java?

    <p>To evaluate expressions based on a condition</p> Signup and view all the answers

    What is the syntax of the ternary operator in Java?

    <p>value_variable = (condition) ? expression1 : expression2</p> Signup and view all the answers

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

    <p>To combine two boolean values</p> Signup and view all the answers

    Which of the following is NOT a type of 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 are the values passed on to a method called?

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

    What is the first step in the execution of a function?

    <p>Function call</p> Signup and view all the answers

    What is the terminating statement in a function body?

    <p>Return statement</p> Signup and view all the answers

    What is allowed in Java that allows defining methods with the same name but different arguments?

    <p>Method overloading</p> Signup and view all the answers

    Which loop in Java is exit controlled and executes the body of the loop at least once even if the initial condition is false?

    <p>Do...while 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

    Which jump statement is used when we want to terminate a particular iteration of a loop in Java?

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

    Which type of loop in Java is used for iterating or repeating a certain set of instructions for a number of times?

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

    What is the alternative for the 'else' part of the if...else if...else structure in Java?

    <p>Default statement</p> Signup and view all the answers

    Which structure in Java is usually used for menu-driven programs?

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

    Which one of the following is true about classes in Java?

    <p>Classes are blueprints for creating objects.</p> Signup and view all the answers

    Which one of the following is true about objects in Java?

    <p>Objects are instances of a class.</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 in Java used for?

    <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 lower CamelCase for writing class names and higher camelCase for writing method names.</p> Signup and view all the answers

    Which type of loop in Java is exit controlled and executes the body of the loop at least once even if the initial condition is false?

    <p>Do...while 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 the 'continue' statement in Java?

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

    What is the syntax for defining a method in Java?

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

    Which access specifier sets the highest level of accessibility for a method in Java?

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

    Which loop in Java is used for iterating or repeating a certain set of instructions for a number of times?

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

    Which of the following is NOT a core concept of Java programming?

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

    What is the purpose of the 'public' keyword in the 'main' method?

    <p>To indicate that the method is accessible from outside the class</p> Signup and view all the answers

    Which keyword is used to declare a method in Java?

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

    What is the purpose of the 'print' method in Java?

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

    What is the purpose of the 'args' parameter in the 'main' method?

    <p>To store arguments passed by the command line while executing the program</p> Signup and view all the answers

    What is the purpose of a conditional statement in Java?

    <p>To execute different code based on a condition</p> Signup and view all the answers

    Which one of the following is true about method overloading in Java?

    <p>Java automatically chooses the function with the matching parameters when method overloading is used.</p> Signup and view all the answers

    Which one of the following is true about arrays in Java?

    <p>Arrays can only store values of the same data type.</p> Signup and view all the answers

    Which one of the following is true about classes in Java?

    <p>Classes are blueprints or templates for creating objects.</p> Signup and view all the answers

    What is the purpose of comments in Java?

    <p>To make the program more readable and understandable.</p> Signup and view all the answers

    What is the syntax for creating an array in Java?

    <p>int[] array = new int[5];</p> Signup and view all the answers

    Which type of loop in Java is used for iterating or repeating a certain set of instructions for a number of times?

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

    Which loop in Java is used to iterate through the elements of an array?

    <p>for-each loop</p> Signup and view all the answers

    What is the syntax for defining a class in Java?

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

    What is the purpose of the 'return' statement in a method?

    <p>To return a value from the method.</p> Signup and view all the answers

    Which one of the following is true about classes in Java?

    <p>A class is a group of objects with some properties and relationships.</p> Signup and view all the answers

    What is an object in Java?

    <p>An identifiable, real-time entity with some characteristics and behavior.</p> Signup and view all the answers

    Which keyword is used to declare a method in Java?

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

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

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

    Which operator is used for exponentiation in Java?

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

    Which of the following is true about the increment and decrement operators in Java?

    <p>They are unary operators.</p> Signup and view all the answers

    Which of the following is true about the logical operators in Java?

    <p>The logical operators can be used with both boolean and non-boolean operands.</p> Signup and view all the answers

    Which of the following is true about the assignment operators in Java?

    <p>The assignment operators in Java can be used to assign values of an expression to a variable.</p> Signup and view all the answers

    Which of the following is true about the ternary operator in Java?

    <p>The syntax of the ternary operator is value_variable = (condition) ? expression1 : expression2;</p> Signup and view all the answers

    More Like This

    Use Quizgecko on...
    Browser
    Browser