Locked lesson.
About this lesson
In this lesson, we learn how to create Object Methods that operate inside your own classes.
Exercise files
Download this lesson’s related exercise files.
46 - Intro To Classes Object Methods.docx57.7 KB 46 - Intro To Classes Object Methods SOLUTION.docx
59.3 KB
Quick reference
Intro To Classes: Object Methods
Object methods allow us to create methods in our classes.
When to use
Use them whenever you want to create methods for your Classes.
Instructions
{
// Create Book Object
Book book1 = new Book("C# Programming", "John Elder", 309);
Console.WriteLine(book1.BigSmall());
}
class Book
{
public string title;
public string author;
public int pages;
public Book(string myTitle, string myAuthor, int myPages)
{
title = myTitle;
author = myAuthor;
pages = myPages;
}
public string BigSmall()
{
if (pages >= 250)
{
return "Big Book"
}
return "Small Book"
}
}
Hints & tips
- Object methods allow us to create methods in our Classes
Lesson notes are only available for subscribers.