Question: package introToclasses; 1 * * A class is a blueprint describing objects in terms of the data they have and the methods that can be

package introToclasses;
1**
A class is a blueprint describing objects in terms of the data they have and the methods that can be acted on them. The methods change the objects data.
The data is anything that describes the object (up to you)
Methods are (C functions) but can only be called (invoked) on an object
and they can change the attributes (values of those variables) of that object
To create an object, we instantiate the class (we create an istance of the class)
ClassName objectName = new ClassName(params);
ClassName acts as a new type
Let's create a class for course
Always name your classes with the first letter capital */
public class Course {
String name;
String instructor;
int numberstudents;
String description;
int credits;
//a mthod to display the values of all these variables:
void print(){
System.out.println("Name: "+
this.name);
System.out.println("Instructor: "+ this.instructor);
System.out.println ("Credits: "+ this.credits);
System.out.println("Number registered: "+ this.numberstudents);
}
System.out.println("Decription: "+ this.description);
void addStudent (){
//increment number student. Always use this.variableName
//will later why.
System.out.println("Adding one student to "+
this.name);
}
this. numberstudents++;
void dropstudent(){
System.out.println("Dropping one student from "+
this.name);
} this numberstudents--;
//Design a method to change the instructor's name, with a new name.
// changeInstructor accepts a string as the new name.
 package introToclasses; 1** A class is a blueprint describing objects in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!