• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

constructor

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



When I compile, this error shows:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol : constructor Subclass(int)
location: class superclass.Subclass
at superclass.Main.main(Main.java:19)
Java Result: 1


Please guide me
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't have constructors in either of your classes that take an int as a parameter.
You do have methods in both classes with the same name as the class.
 
Ranch Hand
Posts: 247
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Constructors have no return type.

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Becuase of void.Understood!

Constructor is a method by the name of class,without any return type,Right?
 
Raza Mohd
Ranch Hand
Posts: 247
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Method must have a return type. then how can you say constructor a method?
 
Sheriff
Posts: 22850
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abalfazl hossein wrote:When I compile, this error shows:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol : constructor Subclass(int)
location: class superclass.Subclass
at superclass.Main.main(Main.java:19)
Java Result: 1


Impossible. When you compile your code you can never get an exception. You probably use an IDE (Eclipse, Netbeans, etc) that allows you to run classes even if they do not compile. Always fix any compiler errors before you run the class.
 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This might help -> constructors
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abalfazl hossein wrote:Constructor is a method by the name of class,without any return type,Right?


A constructor is technically not really a method, even though it somewhat looks like a method. A constructor is a special block of code that is called when you create a new object, to initialize the new object.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a better said is void also a return type which return nothing

so in your code , you doesn't declare any constructor (except the default non-arg constructor that auto generated by compiler), what you have declare is all METHOD ...
so when you try to instantiate a Subclass object , " Subclass s = new Subclass(4); " , the compiler can't find that constructor.
 
reply
    Bookmark Topic Watch Topic
  • New Topic