Comparing Object-Oriented Languages, Page 5
Public MustInherit Class Shape
Protected area As Double
Public MustOverride Function getArea() As Double
End Class
Public Class Rectangle
Inherits Shape
Dim length As Double
Dim width As Double
Sub New(ByVal l As Double, ByVal w As Double)
length = l
width = w
End Sub
Public Overrides Function getArea() As Double
area = length * width
Return area
End Function
End Class
Public Class Circle
Inherits Shape
Dim radius As Double
Sub New(ByVal r As Double)
radius = r
End Sub
Public Overrides Function getArea() As Double
area = 3.14 * (radius * radius)
Return area
End Function
End Class
Module Module1
Sub Main()
Dim myCircle As New Circle(2.2)
Dim myRectangle As New Rectangle(2.2, 3.3)
Dim result As Double
result = myCircle.getArea()
System.Console.Write("Circle area = ")
System.Console.WriteLine(result)
result = myRectangle.getArea()
System.Console.Write("Rectangle area = ")
System.Console.WriteLine(result)
System.Console.Read()
End Sub
End Module
Listing 3c: VB Code for Shape
Conclusion
In this article, you changed gears a bit. Rather than focus on a specific programming concept or technique, you inspected several basic applications and concentrated on how to develop the application in three different object-oriented languages: Java, C#, and VB .NET.
The intent was to whet your appetite. In future articles, you will delve deeper and compare specific programming features and see how the various languages implement these features. You also will compare the similarities and the differences of the various languages. Exploring different languages can help you better understand object-oriented concepts.
References
Weisfeld, M.A. (2005). "The Evolution of Object-Oriented Languages," Developer.com.
About the Author
Matt Weisfeld is a faculty member at Cuyahoga Community College (Tri-C) in Cleveland, Ohio. Matt is a member of the Information Technology department, teaching programming languages such as C++, Java, C#, and .NET, as well as various web technologies. Prior to joining Tri-C, Matt spent 20 years in the information technology industry, gaining experience in software development, project management, business development, corporate training, and part-time teaching. Matt holds an MS in computer science and an MBA in project management. Besides The Object-Oriented Thought Process, which is now in its second edition, Matt has published two other computer books, and more than a dozen articles in magazines and journals such as Dr. Dobb's Journal, The C/C++ Users Journal, Software Development Magazine, Java Report, and the international journal Project Management. Matt has presented at conferences throughout the United States and Canada.
