Java Classes and Objects Flashcards
23 Questions
100 Views

Java Classes and Objects Flashcards

Created by
@FreedRhyme

Questions and Answers

Objects have two properties. One is state. What is the other?

Behavior

The state of an object is stored in _____ _____

Instance variables

The behavior of an object is represented by ______ ______

Instance methods

The job of a _____ is to initialize instance variables at the time an object is created.

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

Nested inside a class declaration are three kinds of declarations. What are they?

<p>Constructor declarations, Variable declarations, Method declarations</p> Signup and view all the answers

The words public and private are _____ _____

<p>Access modifiers</p> Signup and view all the answers

A method is allowed to have _______, which represent data that will be supplied when the method is called.

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

Once a class has been declared, we can create objects that belong to the class. We say that these objects are ______ of the class.

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

An object variable doesn't actually store an object. Instead, it stores a ______ to an object.

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

The keyword ______ is placed before a class name in order to create an object.

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

To perform an operation on an object, we _______ one of the instance methods associated with the object.

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

How do you call an instance method?

<p>object.methodname(arguments)</p> Signup and view all the answers

Reference variables are known as _______ variables in other programming languages.

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

What value can we assign to an object variable to indicate that it doesn't currently store an object?

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

A new object that's been created by copying an existing object is said to be a _______.

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

An object that's no longer accessible through any object variable is said to be _______.

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

An instance method that returns the value of an instance variable is said to be an _______.

<p>Accessor/Getter</p> Signup and view all the answers

An instance method that stores its parameter into an instance variable is said to be an ________.

<p>Mutator/Setter</p> Signup and view all the answers

An object whose instance variables cannot be changed is said to be _______.

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

A method that returns the contents of an object as a string should be named ______.

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

The act of joining two strings together to form a single string is called _______.

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

Which method is used to remove extra space from the beginning and end of a string?

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

What is the value of 11 + 38 + 'THX'?

<p>49THX</p> Signup and view all the answers

Study Notes

Key Concepts of Java: Classes and Objects

  • Objects Properties: Every object has state and behavior; state refers to its condition, while behavior defines its actions.
  • State Storage: The state of an object is maintained through instance variables.
  • Behavior Representation: Instance methods serve to express an object's behavior.
  • Constructor Role: A constructor is responsible for initializing instance variables when an object is instantiated.
  • Declarations in Classes: Classes include three main types of declarations: constructor declarations, variable declarations, and method declarations.

Access Modifiers and Method Parameters

  • Access Modifiers: Keywords like public and private are used to define access control for classes and class members, categorized as access modifiers.
  • Method Parameters: Methods can accept parameters, which are the data inputs provided when a method is invoked.

Object Instances and References

  • Object Creation: After declaring a class, objects can be created as instances of that class.
  • Object Reference: An object variable does not hold the object itself but instead maintains a reference to the object.

Object Creation and Method Invocation

  • Object Instantiation: The keyword new is used to instantiate a new object from a class.
  • Calling Methods: To execute an operation on an object, invoke its instance methods using the syntax object.methodname(arguments).

Variable Concepts and Object Lifecycle

  • Reference Variables: In other programming languages, reference variables are often called pointers.
  • Indicating No Object: The value null can be assigned to an object variable to signify it does not currently refer to an object.
  • Object Cloning: A new object created by duplicating an existing object is referred to as a clone.
  • Garbage Collection: An object is considered garbage when there are no remaining references to it.

Accessor and Mutator Methods

  • Accessor Methods: Methods that retrieve the value of instance variables are known as accessors or getters.
  • Mutator Methods: Methods that update instance variables are classified as mutators or setters.
  • Immutable Objects: An object whose instance variables cannot be altered is termed immutable.

String Handling in Java

  • toString Method: A method intended to return an object’s content as a string should be named toString.
  • String Concatenation: The process of merging two strings into one is termed concatenation.
  • Trim Method: The trim method is utilized to eliminate whitespace from both the beginning and the end of a string.
  • Expression Evaluation: The expression 11 + 38 + "THX" evaluates to 49THX, demonstrating Java's handling of string concatenation with numbers.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

Explore key concepts in Java related to classes and objects with these flashcards. Learn about object properties such as state and behavior, along with instance variables and methods. Perfect for students eager to master Java fundamentals!

More Quizzes Like This

Use Quizgecko on...
Browser
Browser