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 8447179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:07:20+00:00 2026-06-10T10:07:20+00:00

How do you understand the class parameter in scala. Will the compiler add implicit

  • 0

How do you understand the class parameter in scala. Will the compiler add implicit field to the class for the class parameter.
Like

    class Rational(n:Int, d:Int){
        val num = n
        val den = d
        override def toString = n + "/" + d
    }

do we have 4 fields in class Rational (n, d, num, den)? If not, how can we access n and d in method toString. What’s the mechanism behind this?

  • 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-10T10:07:22+00:00Added an answer on June 10, 2026 at 10:07 am

    n and d will become private fields unless they are only used in the constructor, in which case they’re optimised away. num and den will also be private fields, but they get public accessors as well.

    Try this:

    class Test(a: String) {
      println(a)
    }
    

    Then compile and run javap -private Test, which shows all classes and members of the class:

    public class Test extends java.lang.Object{
        public Test(java.lang.String);
    }
    

    Then try with a method that uses that parameter:

    class Test(a: String) {
      println(a)
      def printa { println(a) }
    }
    
    public class Test extends java.lang.Object{
        private final java.lang.String a;        // <- private field
        public void printa();
        public Test(java.lang.String);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to understand what class << self stands for in the next
I understand that you can use the initiate parameter for a Form class from
So suppose I have a class like this one: class Point { private: int
Given the below code, will the method parameter y in Bar(int y) be assigned
Im trying to understand how class generics work and this bit just doesnt make
I don't understand the class TextCompositionEventArgs. There are members of type string named ControlText,SystemText,Text.
What is the difference between these two class declarations? I don't understand why @class
Veterans please forgive me for asking silly question. I understand that a class having
I understand that CoCreateInstance finds the COM server for the given class id, creates
I understand overriding a method/function redefines its implementation in the derived class from its

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.