home > 比較編 > C, C++, Objective-C, Java, C# > objects >

ForNext

Only Do What Only You Can Do

117. define class

VBScript

JScript

Perl

PHP

Python

Ruby

PowerShell

Scala

F#

C

C++

Rational.hpp:
class Rational {
 public:
  int num, denom;
  Rational(int num, int denom);
  virtual ~Rational();
  Rational operator+(Rational& addend);
  static Rational max(Rational& a, Rational& b);
};












C++Builder

VC++

C#

public class Rational {
  public int num;
  public int denom;
}

















Java

public class Rational {
  public int num;
  public int denom;
  public Rational add(Rational o) throws Exception {
    return new Rational(this.num*o.denom + o.num*this.denom,this.denom*o.denom);
  }
  public static Rational max(Rational a, Rational b) {
    return (a.num*b.denom > a.num*b.denom) ? a : b;
  }
}











Objective-C

Rational.h:
#import <Foundation/Foundation.h>
@interface Rational : NSObject {
  int num;
  int denom;
}
@property int num, denom;
-(Rational*) initWith: (int) n: (int) d;
-(Rational*) add: (Rational *) o;
@end
Rational.m:
#include "Rational.h"
@implementation Rational
@synthesize num, denom;
-(Rational*) add: (Rational*) o {
  int sum_n = self.num * o.denom + o.num * self.denom;
  int sum_d = self.denom * o.denom;
  Rational* sum = [[Rational alloc] initWith: sum_n: sum_d];
  return sum;
}
@end

D

VB

VB.NET

Delphi

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system