Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

Swift Protocol To Calculate Area

protocol Polygon {

  func getArea(length: Int, breadth: Int)
}

// conform the Polygon protocol
class Rectangle: Polygon {

  // implementation of method
  func getArea(length: Int, breadth: Int) {
    print("Area of the rectangle:", length * breadth)
  }
}

// create an object
var r1 = Rectangle()

r1.getArea(length:5, breadth: 6)
Comment

PREVIOUS NEXT
Code Example
Swift :: swift how to dereference unsafemutablepointer 
Swift :: Swift Nested Function with Return Values 
Swift :: Allow user to import image 
Swift :: swift methods 
Swift :: Swift Comparison Operators 
Swift :: Swift String and Character Literals 
Swift :: Swift Variables names must start with either a letter 
Swift :: Speech recognizer swiftui 
Swift :: swift navigationbar not working 
Swift :: Arithmetic Operators in Swift 
Swift :: Swift Modify the Elements of an Array 
Swift :: Swift Create Multiple Objects of Class 
Swift :: swift modify dictionary 
Swift :: swift hashable 
Ruby :: ruby struct 
Ruby :: rails get current path 
Ruby :: create table if not exist rails 
Ruby :: integer to string ruby 
Ruby :: rspec add support folder to gem 
Ruby :: Your Ruby version is 3.0.0, but your Gemfile specified 2.7.4 
Ruby :: get date millis rails 
Ruby :: how to delete database in rails 
Ruby :: how to generate a controller in rails 
Ruby :: ruby read stdin 
Ruby :: ruby each do method 
Ruby :: meaning of {} in ruby 
Ruby :: rails get random record 
Ruby :: ruby raise to power 
Ruby :: ruby abs method 
Ruby :: ruby get min value from array 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =