File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "constructor" Watch "constructor" New topic
Author

constructor

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 606



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

Joined: Aug 05, 2005
Posts: 3169
    
  10
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.


Joanne
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

Constructors have no return type.


Good luck!!
A small leak can sink a Gigantic ship.>
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 606
Becuase of void.Understood!

Constructor is a method by the name of class,without any return type,Right?
Raza Mohd
Ranch Hand

Joined: Jan 20, 2010
Posts: 247

hi,

Method must have a return type. then how can you say constructor a method?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150


This might help -> constructors


star chaser..
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 210
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.


SCJP 6, SCWCD 5, SCBCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constructor
 
Similar Threads
Doubt with overloaded super constructor
Inheritance and Serialization
inheritance
sequence of execution
Inheritance, Constructor, Super