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
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.
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.
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.