Menu
Coddy logo textTech

Attributes

Lesson 3 of 12 in Coddy's Basics of Classes and Objects in Java course.

Attributes (also known as fields) are the values inside the classes.

class Point {
	int x = 0;
	int y = 2;
}

In the above example, we create a class named Point with two attributes, x and y with the values 0 and 2 accordingly. 

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

challenge icon

Challenge

Easy

Create a class named Coder with two attributes:

  • A string typed value named name with your name
  • An integer typed value named age with your age

Try it yourself

// Write code here

All lessons in Basics of Classes and Objects in Java