[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Doubt

Posted on 1998-08-26
2
Medium Priority
?
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
fontaine earned 120 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

649 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