Computer Science, asked by jyotikajulie, 8 months ago


Name the main parts of class​

Answers

Answered by khushi19125
5

2.7. Parts of a Java Class

A Java class defines what objects of the class know (fields) and can do (methods). The class also defines how to initialize the fields when the object is first created (constructors).

2.7.1. Fields - Instance Variables

Fields hold the data for an object. Fields record what an object needs to know to do work in the program. Fields are also called instance variables or object variables or properties.

All fields on the AP CS A exam should be declared private. Think of private as like your diary. Only you should have direct access to it. In this case private means that only the code in this class can directly access the field values.

Note

Fields are declared right after the class declaration. They start with private then the type of the field and then a name for the field.

The Person class declares two fields: name and cell. Name is the person’s name and cell is their cell phone number. These are both things that you might need to know about a person.

Clickable (name_fields)

2.7.2. Constructors

Constructors don’t actually construct the object. The class makes the object and then executes a constructor to initialize the values of the fields (instance variables). You will only work with public constructors on the exam.

Note

Constructors are specified after the fields and before any methods. They typically start with public and then the name of the class. They can take data (specified in parentheses) which is used to initialize the fields.

Clickable (name_constructor)

2-7-3: What best describes the purpose of a class’s constructor?

A. Determines the amount of space needed for an object and creates the object

B. Names the new object

C. Return to free storage all the memory used by this instance of the class.

D. Initialize the fields in the object

2.7.3. Methods

Methods define what an object can do or the behavior of the object.

Most methods you work with on the exam will be public.

Note

Methods define what the object can do. Methods are specified after the constructors. They typically start with public then a type, then the name of the method. They can take data as input which is specified in parentheses.

The Person class has methods for getting the name and cell phone and for setting the cell phone. Methods that get information from an object are called getters or accessors. Methods that set field values are called setters or mutators.

Answered by shishir303
0

Name the main parts of the class​ in Java?

The main parts of Java are as follows.

Variable : A variable is a reserved memory location in which the value is inserted. This location is used to store the value. By giving a name to the value, the value becomes a safe place in the memory, it is called a variable.

Constructor : Constructor is a special type of method in Java, which is used to initialize an object of a Java class. The constructor is a very important part of the Java class. Without it, the Java class cannot function.

Method : It is a block of Java class, it works only when a command is given to it. Data known as a parameter can be passed to a method. A method is used to perform certain actions. Such actions are known as functions.

#SPJ3

◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌◌

Know something more...

A kind of computer software which is used exclusively by computer programmers.

A. Application Software

B. Programming Software

C. Computer Software

D. System Software

https://brainly.in/question/28456891

Which of the following correctly defines the computer system?

a. hardware

b. software

c. hardware + software + data

d. hardware + software + data + human being

https://brainly.in/question/1504943

Similar questions