fork download
  1. public class Mobile {
  2. public String brand;
  3.  
  4. // Constructor (Jab object create hoga, yeh chalega)
  5. public Mobile(String brandName) {
  6. this.brand = brandName;
  7. }
  8.  
  9. // Instance Method
  10. public void showBrand() {
  11. System.debug('Yeh mobile ' + this.brand + ' ka hai!');
  12. }
  13. }
  14.  
  15. // Object bana rahe hain
  16. Mobile m1 = new Mobile('iPhone');
  17. Mobile m2 = new Mobile('Samsung');
  18.  
  19. // Instance method ko call kar rahe hain
  20. m1.showBrand(); // Output: Yeh mobile iPhone ka hai!
  21. m2.showBrand(); // Output: Yeh mobile Samsung ka hai!
  22.  
Success #stdin #stdout #stderr 0.02s 10532KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #Mobile
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #Mobile (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
Object: nil error: did not understand #associationAt:ifAbsent:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject(Object)>>doesNotUnderstand: #associationAt:ifAbsent: (SysExcept.st:1448)
DeferredVariableBinding>>resolvePathFrom: (DeferBinding.st:115)
DeferredVariableBinding>>value (DeferBinding.st:69)
UndefinedObject>>executeStatements (prog:21)
stderr
./prog:4: parse error, expected '}'
./prog:21: expected expression