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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:28:11+00:00 2026-05-25T23:28:11+00:00

object JDWhileLoop { def main(args: Array[String]) { var index:Int = 0 while( index<=10) {

  • 0
object JDWhileLoop
{               
                def main(args: Array[String])

                {
                        var index:Int = 0
                        while( index<=10)
                        {

                        println("index="+index)
                        index= index+1              

                        }

                }       
}                   

here is the error

JDWhileLoop.scala:3: error: only classes can have declared but
undefined members
def main(args: Array[String])
^

I got this simple code and try to make work,but is not ,I dont know why.please help me. thanks

  • 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-05-25T23:28:12+00:00Added an answer on May 25, 2026 at 11:28 pm

    That’s formatting error. This should be fine:

    object JDWhileLoop
    {               
                    def main(args: Array[String]) 
                    {
                            var index:Int = 0
                            while( index<=10) {
                            println("index="+index)
                            index= index+1           
                            }
                    }       
    } 
    

    In your code def main(args: Array[String]) treated as an abstract method (without body) followed by some code block in object inner body definition.

    Note that in scala the following braces style is preffered

    def foo (args: Bar) {
      //some work 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

object TestClass { def main (args: Array[String]) { println(Hello World); val c = List
object NGram{ def main(args: Array[String]) { //args(0) = textfile //args(1) = size of n-grams
object NoSense { def main(args: Array[String]) { val value = true match { case
object(stdClass)[1] public 'inbox' => array 0 => object(stdClass)[2] public 'from' => string '55512351' (length=8)
object(SimpleXMLElement)#1 (3) { [@attributes]=> array(1) { [responsecode]=> string(3) 200 } [nextpage]=> object(SimpleXMLElement)#2 (0) {
Object ele=a.get(i); if(ele instanceof java.lang.Integer){//cast to integer: print(found Int); }else{ //cast to string: print(found:
Object mainForumRecords=request.getAttribute(mainForumRecords); if(mainForumRecords instanceof ArrayList) { Iterator<MainForumRecordBean> recordIterator=((ArrayList<MainForumRecordBean>)mainForumRecords).listIterator(); while(recordIterator.hasNext()) { out.println(<tr>); MainForumRecordBean record=recordIterator.next(); {
object s; s = abc; int n = ((string)s).Length; Is there any way of
Object o = new Long[0] System.out.println( o.getClass().isArray() ) System.out.println( o.getClass().getName() ) Class ofArray =
Object-relational mapping has been well discussed, including on here. I have experience with a

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.