Solved

Doubt

Posted on 1998-08-26
2
181 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

820 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