STI IT1712 Classes and Methods Quiz

FortuitousLasVegas avatar
FortuitousLasVegas
·
·
Download

Start Quiz

Study Flashcards

10 Questions

What does the void keyword denote in a method?

It signifies the method does not return a value

What is the difference between a parameter and an argument in a method?

Parameters are the list of variables in a method declaration, while arguments are the actual values passed when invoking the method

Why must the data type of the return value match the declared return type in a method?

To prevent errors and ensure consistency in data handling

What do instance variables refer to in Java?

Variables declared outside methods, constructors, or blocks

What purpose does 'this' keyword serve in Java?

Represents an object's name receiving the method call within a method definition

What is the main purpose of a mutator method in Java?

To change the data stored in one or more private instance variables

How does a private method in Java differ from a public method?

A private method cannot be invoked outside its class, while a public method can.

What is encapsulation in object-oriented programming?

The process of combining data and actions into a single item

In Java, what does a UML Class Diagram display?

The structure of a class including name, variables, and methods

How are references handled in Java with respect to objects?

Variables hold memory addresses of objects

Study Notes

Classes and Methods

  • The void keyword indicates that a method does not return a value.
  • A parameter is a list of variables in a method declaration, while an argument is the actual value passed when the method is invoked.
  • The data type of the return value must match the declared return type.

Instance Variables and Local Variables

  • Instance variables are variables declared outside a method, constructor, or block.
  • Local variables are variables declared within a method definition and are only visible to that method.

The this Keyword

  • The this keyword represents the object's name receiving the method call within a method definition.

Information Hiding and Encapsulation

  • Information hiding is a mechanism for restricting access to some of an object's components.
  • Advantages of information hiding include:
    • Making components easier to understand and use
    • Simplifying modification and repair
    • Facilitating re-use
  • If an instance variable is public, there are no restrictions on where its name can be used.
  • If an instance variable is private, its name cannot be used to access it outside of the class definition.
  • Accessor methods are public methods that return data from private instance variables.
  • Mutator methods are public methods that change the data stored in one or more private instance variables.

Encapsulation

  • Encapsulation is the process of combining data and actions into a single item.
  • It groups instance variables and methods into a class and hides implementation details.

UML Class Diagram

  • The UML Class Diagram describes the structure of a class by displaying the class name, variables, and methods.

Objects and References

  • A variable of a class type contains the memory address of the object named by the variable, rather than the object itself.
  • The address of the object's memory location is called a reference to the object.
  • Class types are reference types whose variables hold references or memory addresses.
  • Use the equals() method for comparison, instead of ==.

Test your knowledge on class methods and definitions in STI IT1712! Learn about the void keyword, parameters versus arguments, return types, and instance variables.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

STI and Urethritis Quiz
10 questions
STI Risk Factors for Seafarers
10 questions
STI Vocabulary Quiz
5 questions

STI Vocabulary Quiz

PreferableAstronomy avatar
PreferableAstronomy
STI
25 questions

STI

GentleGreekArt avatar
GentleGreekArt
Use Quizgecko on...
Browser
Browser