Solved

Doubt

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
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.

758 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

19 Experts available now in Live!

Get 1:1 Help Now