Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

KAM India Edition Question 6.27

 
Mahesh Bansal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following code, which statements are true ?
public interface HeavenlyBody {String describe();}
class Star implements HeavenlyBody {
String starname;
public String describe() { return "star" + starname;}
}
class Planet {
String name;
Star Orbitting ;
public String describe() {
return "planet"+name+"orbiting"+orbiting.describe();
}
}
Select all valid answers
a) The code will fail to compile
b) The use of aggregation is justified, since plant has-a star.
c) The code will fail to compile if the name starName is replaced with the name bodyName throughout the Star class definition.
d) The code will fail to compile if the name starName is replaced with the name name throughout the Star class definition.
e) An instance of Planet is a valid instance of a HeavenlyBody.
 
shabbir zakir
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI!
Given the following code, which statements are true ?
public interface HeavenlyBody {String describe();}
class Star implements HeavenlyBody {
String starname;
public String describe() { return "star" + starname;}
}
class Planet {
String name;
Star Orbitting ;
public String describe() {
return "planet"+name+"orbiting"+orbiting.describe();
}
}
Select all valid answers
a) The code will fail to compile
b) The use of aggregation is justified, since plant has-a star.
c) The code will fail to compile if the name starName is replaced with the name bodyName throughout the Star class definition.
d) The code will fail to compile if the name starName is replaced with the name name throughout the Star class definition.
e) An instance of Planet is a valid instance of a HeavenlyBody.
THe code will fail to compile stating that class or variable orbitting is not defined.
 
Mahesh Bansal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code will compile but throw an error at run time.
Mahesh
 
Sandeep Chaturvedi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is KAM India (is it a mock exam on web? Can you tell the site or email me at chaturs@hotmail.com
Thanks
 
natarajan meghanathan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only correct answer is option b.
 
shabbir zakir
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
The code will fail to compile stating that undefined variable or class orbiting on Line 10.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic