dcsimg
August 14, 2018
Hot Topics:

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.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date