aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes kathy sierra scjp 1.6 book question  doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "kathy sierra scjp 1.6 book question  doubt" Watch "kathy sierra scjp 1.6 book question  doubt" New topic
Author

kathy sierra scjp 1.6 book question doubt

dilip kumarr
Greenhorn

Joined: Jan 31, 2010
Posts: 6

question:
what is the result?

class Top {
public Top(string s)
{
System.out.print("b");
}
public class Bottom2 extends Top{
public Bottom2(String s)
{
System.out.print("D");
}
public static void main(String [] args){
new Bottom2("c");
System.out.println(" ");
}
}

doubt:
1.wats the meaning of : new Bottom2("c"); in the above program.

kindly clear my doubt...........

thanks in advance..............



Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400


it means you are calling the overloaded constructor of Bottom2 class.


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Shailesh Phatak
Ranch Hand

Joined: Aug 27, 2009
Posts: 64
since the base class does not have an explicit zero arg contructor it will produce an error


See Dreams With Open Eyes And Make It Real
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

by the way there are some errors in your code...
Nur Ahmed
Greenhorn

Joined: Mar 10, 2010
Posts: 1
I think M M kaimkhani already gave you the answer in his first response.

new Bottom2("c") is the call to the constructor Bottom2 which has an implicit call to the super (not visible in this piece of code though. you have to code it in as if you have a constructor with arguments the compiler will not provide you a similar one or a default one). //using braces in java is tricky ... :-) all I meant is, for the minimum, you will need to add something like super(""); in the Bottom2 constructor.

So, to sum up, the logic/catch is to call the super class constructor first. Try running the code without "new Bottom2("c")" ;-)


Afzal Rehman
Ranch Hand

Joined: Dec 16, 2009
Posts: 39
First of all code is wrong
1- There is } closing bracket is missing.
2- There is no no-arg constructor is in Top class.

So Code will fail ...


SCJP 6.0
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Dilip please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: kathy sierra scjp 1.6 book question doubt