Programming in Dart: Classes

Jun 28 2022 · Dart 2.17, Flutter 3.0, DartPad

Part 1: Understand Classes

02. Create a Class

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 01. Introduction Next episode: 03. Challenge: Create a Custom Class

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Dart is known as an object oriented language. This means, we use objects as a way to organize our code. But what does this even mean? Well, when you start writing a program, you end up breaking that program into smaller tasks. For instance, some parts of the program will respond to user input. Other parts will save or load data. Other parts may even fetch things over a network and so forth.

class Person {

}
var firstName = '';
var lastName = '';
void sayHello() {
    print('Hello, my name is $firstName $lastName');
}
var weatherMan = Person();
weatherMan.firstName = 'Phil';
weatherMan.lastName = 'Connors';
print(weatherMan.firstName);
var singer = new Person();
var singer = Person();
singer.firstName = 'Janet';
singer.lastName = 'Joplin';
weatherMan.sayHello();
singer.sayHello();