Solved

Doubt

Posted on 1998-08-26
2
179 Views
Last Modified: 2010-03-30
When i compile the below source code i am getting the below error  please help me in solving this error.

Thank u in advance,
seena
Source Code
===========
package c06;

class WaterSource {
  private String s;
  WaterSource() {
    System.out.println("WaterSource()");
    s = new String("Constructed");
  }
  public String toString() { return s; }
}

public class SprinklerSystem {
  private String valve1, valve2, valve3, valve4;
  WaterSource source;
  int i;
  float f;
  void print() {
    System.out.println("valve1 = " + valve1);
    System.out.println("valve2 = " + valve2);
    System.out.println("valve3 = " + valve3);
    System.out.println("valve4 = " + valve4);
    System.out.println("i = " + i);
    System.out.println("f = " + f);
    System.out.println("source = " + source);
  }
  public static void main(String[] args) {
    SprinklerSystem x = new SprinklerSystem();
    x.print();
  }
}


Error File
============
Compiling C:\ssjava\chap6\exer1.java
C:\ssjava\chap6\exer1.java:20: Public class c06.SprinklerSystem must be defined in a file called "SprinklerSystem.java".
public class SprinklerSystem
             ^
1 error
0
Comment
Question by:seena
2 Comments
 
LVL 5

Accepted Solution

by:
fontaine earned 30 total points
ID: 1222588
In Java, you are only allowed to define one public class per file. The name of the file has
to correspond to the name of the public class. In your example, the public class is
SprinklerSystem. Hence, the file containing the program has to be called
SprinklerSystem.java. The filename exer1.java would be valid if the name of the public class
was exer1.
0
 

Author Comment

by:seena
ID: 1222589
Hi,

      Thank u for ur answer.  It really works.

Thanks
Srini

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 84
wordappend challenge 8 143
Saving Tweets with emojis using Twitter4J in a Mysql table 2 73
java. non-English characters encoding problem. intellij idea 3 73
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now