Object-Oriented Programming Lecture: Class Members Quiz
16 Questions
1 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

Where are member variables defined in a class?

  • As parameters (arguments)
  • As class variables (static fields) (correct)
  • As local variables
  • Inside methods
  • Which type of method is declared as non-static in a class?

  • Local method
  • Class method
  • Static method
  • Instance method (correct)
  • What happens to member variables that are declared but not initialized?

  • They are automatically assigned a null value
  • They remain uninitialized
  • They cause a compilation error
  • They are set to a default value by the compiler (correct)
  • What is the default value for an uninitialized long data type variable?

    <p>0L</p> Signup and view all the answers

    Where are static members (variables and methods) of a class defined?

    <p>As class variables and static methods</p> Signup and view all the answers

    Which type of variable is used to store the state of an object in a class?

    <p>Instance variable (non-static field)</p> Signup and view all the answers

    What happens if you attempt to compile and run method m in class Test?

    <p>Compilation fails</p> Signup and view all the answers

    How are instance variables of an object accessed from another class?

    <p>:objectName.variableName</p> Signup and view all the answers

    Which of the following correctly accesses instance methods from another class?

    <p>:objectName.methodName(argument)</p> Signup and view all the answers

    In the given example, what will be the output of c1.area after calling c1.setArea()?

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

    In the BankAccount class, what happens when you call the withdraw method?

    <p>Decreases the account balance by the specified amount</p> Signup and view all the answers

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

    <p>To refer to the current instance of the class</p> Signup and view all the answers

    What is the result of attempting to run method m2 in class A?

    <p>: No output is printed</p> Signup and view all the answers

    What happens if you attempt to access an uninitialized instance variable in Java?

    <p>: It results in a compile-time error</p> Signup and view all the answers

    What is the role of 'this' in the BankAccount class constructor?

    <p>: To initialize instance variables</p> Signup and view all the answers

    In Java, how are instance variables in instance methods related to the calling object?

    <p>They are always prefixed with 'this.' and relate to the calling object</p> Signup and view all the answers

    More Like This

    Use Quizgecko on...
    Browser
    Browser