October 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Comparing Object-Oriented Languages

  • December 6, 2007
  • By Matt Weisfeld
  • Send Email »
  • More Articles »
Public Class IntSquare

   Dim squareValue As Integer

   Property accessSquareValue() As Integer

      Get
         Return squareValue
      End Get

      Set(ByVal Value As Integer)
         squareValue = Value
      End Set

   End Property

   Public Function calculateSquare(ByVal Value As Integer) _
      As Integer

      System.Console.WriteLine(Value)

      squareValue = Value * Value

Return squareValue> End Function End Class

Listing 1c: VB Code for IntSquare Class

Person

The Person example creates a simple class that includes the code to illustrate the object-oriented concept of encapsulation. You create attributes and the various accessor/mutator methods (getters and setters).

public class Person{

   //Attributes
   private String name;
   private String address;

   //Methods
   public String getName(){
      return name;
   }
   public void setName(String n){
      name = n;
   }

   public String getAddress(){
      return address;
   }
   public void setAddress(String adr){
      address = adr;
   }

}

Listing 2a: Java Code for Person Class

public class Person{

   //Attributes
   private string name;
   private string address;

   //Methods
   public string getName(){
      return name;
   }
   public void setName(string n){
      name = n;
   }

   public string getAddress(){
      return address;
   }
   public void setAddress(string adr){
      address = adr;
   }

}

Listing 2b: C# Code for Person Class

Public Class Person

   Dim name As String
   Dim address As String

   Property accessName() As String

      Get
         Return name
      End Get

      Set(ByVal Value As String)
         name = Value
      End Set

   End Property

   Property accessAddress() As String

      Get
         Return address
      End Get

      Set(ByVal Value As String)
         address = Value
      End Set

   End Property

End Class

Listing 2c: VB Code for Person Class





Page 3 of 5



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel