File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor

 
abalfazl hossein
Ranch Hand
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Raza Mohd
Ranch Hand
Posts: 247
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructors have no return type.

 
abalfazl hossein
Ranch Hand
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • 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
Java MyEclipse IDE MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Method must have a return type. then how can you say constructor a method?
 
Rob Spoor
Sheriff
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This might help -> constructors
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Lee Kian Giap
Ranch Hand
Posts: 213
  • 0
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic