Chapter 8 Classes and Objects

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is a class?

A class is a template for objects. It defines the properties of objects and provides constructors for creating objects and methods for manipulating them. A class is also a data type. You can use it to declare object reference variables. An object reference variable that appears to hold an object actually contains a reference to that object

Describe a set method

A set method is referred to as a setter (or mutator). To enable a private data field to be updated, provide a set method to set a new value.

What is a static variable?

A static variable is shared by all objects of the class. A static method cannot access instance members of the class

What is an instance variable or method?

An instance variable or method belongs to an instance of a class. Its use is associated with individual instances.

What is an object?

An object is an instance of a class. You use the new operator to create an object, and the dot operator (.) to access members of that object through its reference variable.

How can we create an array of circle objects?

Circle[] circleArray = new Circle[10]; //to initialize: for (int i = 0; i < circleArray.length; i++){ circleArray[i] = new Circle(); }

What is a get method?

Colloquially, a get method is referred to as a getter (or accessor). To make a private data field accessible, provide a get method to return its value.

What happens if no package is defined?

If a class is defined without the package statement, it is said to be placed in the default package. Java recommends that you place classes into packages rather using a default package.

What happens if no visibility modifier is used?

If no visibility modifier is used, then by default the classes, methods, and data fields are accessible by any class in the same package. This is known as package-private or package-access.

What's the purpose of making data fields private?

Making data fields private protects data and makes the class easy to maintain.

Can you invoke an instance method from a static method?

No. You cannot invoke an instance method or instance variable from a static method.

What are packages used for?

Packages can be used to organize classes. To do so, add the following noncomment and nonblack statement in the program: package packageName;

What does the default modifier do?

The default modifier restricts access to a package

What does the private modifier do?

The private modifier makes methods and data fields accessible only from within its own class. An object can access its private members if it is defined in its own class.

What is data field encapsulation?

To prevent direct modifications of data fields, you should declare the data fields private, using the private modifier. This is known as data field encapsulation.

What is UML?

Unified Modeling Language (UML) is a general-purpose modeling language in the field of software engineering. It provides a set of graphic notation techniques to create visual models of object-oriented software-intensive systems.

What is a visibility modifier?

Visibility modifiers can be used to specify the visibility of a class and its members.

Can an array hold objects?

Yes. An array can hold objects (instances) as well as primitive type values.

Can you invoke an static method from an instance method?

Yes. You can invoke instance methods, static methods, instance variables, and static variables from an instance method

What is the public visibility modifier?

You can use the public visibility modifier for classes methods, and data fields to denote that they can be accessed from any other classes.

What are two other modifiers that Java provides?

private and protected modifiers

How do you declare a constant variable that can be accessed by all methods in the class?

use the "final static" syntax. For example. final static double PI = 3.14159


Kaugnay na mga set ng pag-aaral

Spanish 2, Capitulo 2, Desafio 1

View Set

Principles of Marketing Exam Chapter Seven

View Set

Chapter 14: Accounts Payable and Other Liabilities

View Set