• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where is the Object o1 come from?

 
Megan Lion
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following classes which of the following will compile without error?
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();
}
}
1) o1=o2;
2) b=ob;
3) ob=b;
4) o1=b

correct answer is 1,2,4, i can not understand why the choice 1 and 4 is correct.Where the Object 01 come from ,what mean ?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by cclion:
Where the Object 01 come from?

The variable o1 comes from the line:

Since o1 is of type Object, any reference to an object in Java can be assigned to it because all classes either implicity or explicity extend Object.
Corey
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cclion,
Please, read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you for your cooperation.
 
Nazmul Huda Sarkar
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi cclion
the object is o1 not 01....and any object or interface can be assigned to Object type..here o1
in the exam read question very carefully..
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cclion,
you can click on the following link
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=edit_my_profile
and change your publicly displayed name (the first textfield). Thank you for your cooperation.
 
Megan Lion
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank Corey, thank Nazmul, i see .
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object is the base class for all Java classes hence can hold refernce to any object.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lion,
I'm sorry to come back again and again with this "name" thing, but yours still does not comply with our rule which specifies that it should be composed of your first name, a space and your last name.
Please do the necessary. Thank you for your cooperation.
 
Megan Lion
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry to take you so much trouble,dear Valentin Crettaz.Thanks for your patience,thank you very much.
I have changed my name ,does it right now ?!
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's perfect Megan
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic