This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt about modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt about modifier" Watch "Doubt about modifier" New topic
Author

Doubt about modifier

Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
public class inheritex
{
int i=5;
}
class inheritex1 extends inheritex
{
int i=3;
static void main(String args[])
{
inheritex1 ex=new inheritex1();
System.out.println(ex.i);
}
}

Here i am getting the error, class inheritex is public and should be declared in a file named inheritex.java
what's wrong in this?
please explain me this....

Thanks
Preparing scjp5
Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
sorry here is the correct code!


public class inheritex
{
int i=5;
}
class inheritex1 extends inheritex
{
int i=3;
public static void main(String args[])
{
inheritex1 ex=new inheritex1();
System.out.println(ex.i);
}
}

Here i am getting the error, class inheritex is public and should be declared in a file name inheritex.java
what's wrong in this?
please explain me this....

Thanks
Preparing scjp5
anu kuntala
Greenhorn

Joined: Sep 25, 2008
Posts: 17
hi Preetha,

You have not mentioned your file name. What have you given as file name.
check for spelling mistakes.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by Preetha Arun:

Here i am getting the error, class inheritex is public and should be declared in a file name inheritex.java


If you have a Class definition whose access specifier is 'public' , then you must save the file with public class name !

Like In your example , your file name is "inheritex.java" !

For further information , follow this link !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
sumi rankan
Ranch Hand

Joined: Apr 07, 2008
Posts: 46
If a class x is declared public it should be saved in the file x.java.otherwise the compiler complains.This restriction is not enforced if both the classes have default access.
Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
thank you all ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt about modifier
 
Similar Threads
GridbagConstraints
Inheritance Question
Adding Arrays
Declaration and definition
Correct implementation of hashcode()