This program creates two Building objects : Class Definition « Class Interface « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Class Interface » Class DefinitionScreenshots 
This program creates two Building objects
This program creates two Building objects
 
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// This program creates two Building objects. 
 
  
using System;  
  
class Building {   
  public int floors;    // number of floors 
  public int area;      // total square footage of building 
  public int occupants; // number of occupants 
}   
   
// This class declares two objects of type Building.   
public class BuildingDemo1 {   
  public static void Main() {   
    Building house = new Building();   
    Building office = new Building()
 
    int areaPP; // area per person 
   
    // assign values to fields in house 
    house.occupants = 4;  
    house.area = 2500;  
    house.floors = 2;  
 
    // assign values to fields in office 
    office.occupants = 25;  
    office.area = 4200;  
    office.floors = 3;  
   
    // compute the area per person in house 
    areaPP = house.area / house.occupants;  
   
    Console.WriteLine("house has:\n  " 
                      house.floors + " floors\n  " 
                      house.occupants + " occupants\n  " 
                      house.area + " total area\n  " 
                      areaPP + " area per person")
 
    Console.WriteLine()
 
    // compute the area per person in office 
    areaPP = office.area / office.occupants;  
 
    Console.WriteLine("office has:\n  " 
                      office.floors + " floors\n  " 
                      office.occupants + " occupants\n  " 
                      office.area + " total area\n  " 
                      areaPP + " area per person")
  }   


           
         
  
Related examples in the same category
1.simulate a bank account
2.Using Initializers
3.A simple inventory exampleA simple inventory example
4.Declaring and Defining Classes
5.Declaring Class Instances
6.Assign value to classAssign value to class
7.Declare class and use itDeclare class and use it
8.Illustrates how to declare classes, object references, and create objectsIllustrates how to declare classes, object references, and create objects
9.Illustrates how to assign default values to fields using initializersIllustrates how to assign default values to fields using initializers
10.illustrates how to use a 'has a' relationshipillustrates how to use a 'has a' relationship
11.Illustrates nested classesIllustrates nested classes
12.Multiple constructors in a class definitionMultiple constructors in a class definition
13.Demonstrate the use of a nested class to contain dataDemonstrate the use of a nested class to contain data
14.Show name hiding in a derived classShow name hiding in a derived class
15.Illustrates hidingIllustrates hiding
16.Variable in and out a classVariable in and out a class
17.Create classCreate class
18.A program that uses the Building classA program that uses the Building class
19.Return an objectReturn an object
20.Uses a class from Example16_3a.cs
21.A Simple C# ClassA Simple C# Class
22.Persons Info class
23.Message class
24.Point class
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.