7 Replies - 203 Views - Last Post: 03 October 2012 - 07:53 PM Rate Topic: -----

#1 mm chohan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 12

program not run on my computer

Posted 03 October 2012 - 01:34 PM

class farhan
{
void b()
{
System.out.println("farhan se milo ");
}
}
class Muzammil extends farhan
{
public static void main(String...a)
{
farhan f=new farhan();
f.b();
System.out.println("program kyo bnate ho");

}}
Is This A Good Question/Topic? 0
  • +

Replies To: program not run on my computer

#2 Kakerergodt  Icon User is offline

  • D.I.C Head

Reputation: 87
  • View blog
  • Posts: 201
  • Joined: 01-May 12

Re: program not run on my computer

Posted 03 October 2012 - 01:38 PM

You need to have the main method in a public class.
Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: program not run on my computer

Posted 03 October 2012 - 07:17 PM

which match the name of the .java file
Was This Post Helpful? 1
  • +
  • -

#4 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: program not run on my computer

Posted 03 October 2012 - 07:22 PM

In short, add public to your class name definition, and put it in a file named with your class name and with an extension of .java. ^^
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: program not run on my computer

Posted 03 October 2012 - 07:33 PM

Actually does not really need to be public, can be protected

Just move the main() class to farhan and it will work
Was This Post Helpful? 1
  • +
  • -

#6 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: program not run on my computer

Posted 03 October 2012 - 07:39 PM

That's new to me, thanks! I'll probably read up on it once I reach classes on the Java Tutorials. ^^
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: program not run on my computer

Posted 03 October 2012 - 07:47 PM

fromTheSprawl examples that are showed in this forum are always extreme and do not reflect what you would see in real life.

In real life nobody would bother extend a class which have only a few lines (but for educational purposes) so in real life clas farghan would have a few dozens lines
so nobody would extend it in the same .java file

so the showed case would never happen in real life
Was This Post Helpful? 1
  • +
  • -

#8 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: program not run on my computer

Posted 03 October 2012 - 07:53 PM

Well, as much as possible I would like to know as much as how stuff works in Java, like this one, I think it is simple but I didn't know that it could still run without the public class. I might have misguided him if not for your correction. ^^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1