Scala regular Exercise B

Source: Internet
Author: User

Package Com.hengheng.scalaclass Point (Val x:int, Val y:int) {val Isoriginal:boolean = {   x = = 0 && y = = 0}}class Talkpoint (x:int, Y:int) extends point (x, y) {  def talk () = {    println ("My position is (" + x + "," + Y + ")")  }}class happytalkpoint (x:int, Y:int) extends Talkpoint (x, y) {  override Def talk () {    println ("I ' A M happy! ")    Super.talk ()  }}abstract class Animal {  def walk (Speed:int)    def breathe () = {    println ("Aninamal Breathes. ")  }} Class Dog extends Animal {  override def walk (speed:int) = {    println ("Dog walks, speed are" + speed)  }}obj  ECT application{  def main (args:array[string]) {   val p = new Point (0, 0)   println ("point info" + p.x + "," + p.y + ")")   println (p.isoriginal)   val pp = new Talkpoint (3,4)   Pp.talk ()   val PPP = new Happytalkpoint (0, 0)   Ppp.talk ()   val d = new Dog ()   D.walk (Ten)   d.breathe  }}

Output:

Point info (0,0)
True
My position is (3,4)
I ' am happy!
My position is (0,0)
Dog walks, speed is 10
Aninamal breathes.

Scala regular Exercise B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.