Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9236717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:21:51+00:00 2026-06-18T07:21:51+00:00

Why does scala complains for below code? scala> class Http(var status: Int) defined class

  • 0

Why does scala complains for below code?

scala> class Http(var status: Int)
defined class Http

scala> case class Post(url: String, data: String, status: Int) extends Http(status)
<console>:8: error: overriding variable status in class Http of type Int;
 value status needs `override' modifier
       case class Post(url: String, data: String, status: Int) extends Http(status)
                                                  ^

scala> case class Post(url: String, data: String, sta: Int) extends Http(sta)
defined class Post

But this runs fine.

scala> class C(boo:Int)
defined class C

scala> case class D(far:Int, boo:Int) extends C(boo)
defined class D
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:21:53+00:00Added an answer on June 18, 2026 at 7:21 am

    var status: Int will create accessor methods, something like

    def status() = this.status
    def status(status: Int) {this.status = status}
    

    case class creates these methods by default, so you have two methods with same signature, and scala requires you to add override keyword when overriding methods.

    without var you only create class fields and they are not overridden.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given: case class Person(name: String) and trying to do: scala> List(Person(Tom), Person(Bob)).sorted results in
Suppose I have the following Scala code: class Foo(a: Int) class Bar(b: Buffer[Int]) extends
Does Scala have a version of Rubys' each_slice from the Array class?
Does Scala provide a built-in class, utility, syntax, or other mechanism for converting (by
I don't understand. Why does Scala support override method as field: abstract class A
When writing the following code in scala var m = Map((0,1) -> a) m
I'm really wondering what this code does: scala> import java.nio.file._ import java.nio.file._ scala> Files.copy(Paths.get(),
What does Scala's @ operator do? For example, in the blog post Formal Language
Given a Map[String, Int] in Scala, I want to create a trait that allows
Suppose I have a stupid little case class like so: case class Foo(name: String,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.