-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Program for Class Variable i.e. @@x | ||
|
||
class Filly | ||
# Initialize our class variables | ||
@@count = 0; | ||
def initialize(l,b) | ||
@length = l | ||
@breadth = b | ||
|
||
# @@count = @@count + 1 | ||
@@count += 1 | ||
|
||
end | ||
|
||
def printcount() | ||
puts "Number of objects created is: #{@@count}" | ||
end | ||
end | ||
|
||
# Create two objects | ||
filly1 = Filly.new(30, 10) | ||
filly2 = Filly.new(20, 5) | ||
|
||
# Call class method to print box count | ||
filly1.printcount | ||
filly2.printcount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Program for Class Variable i.e. @@x with self method | ||
|
||
class Filly | ||
# Initialize our class variables | ||
@@count = 0; | ||
def initialize(l,b) | ||
@length = l | ||
@breadth = b | ||
|
||
# @@count = @@count + 1 | ||
@@count += 1 | ||
|
||
end | ||
|
||
def self.printcount | ||
puts "Number of objects created is: #{@@count}" | ||
end | ||
end | ||
|
||
# Create two objects | ||
filly1 = Filly.new(30, 10) | ||
filly2 = Filly.new(20, 5) | ||
|
||
# Call class method to print box count | ||
Filly.printcount |