can someone plz explain why each option is valid or invalid..i have no clue of waht is going on in these questions? all i can see are they are being multiplied?.. i do not understand these attributes and instances and cannot find any helpful resources either? i know in the question below does not ask for attributes or instances but if u could in brief about the classes?
49. Given the following:-
class H {
public int z;
public String x;
class G extends H {
public double w;
public double y( ) { }
Which one of the following sets of statement is not valid:-
a) H r = new H( ); r.z = 99;
b) G r = new G( ); r.z = 9;
c) G r = new G( ); double d = r.y( );
d) G r = new G( ); r.w = 9.9;
e) H r = new H( ); r.x = 9.9;

Given the following Java code:-
public class D{
private int a;
private String c;
Which one of the following sets of statements is valid
a) D p = new D( ); p.a = p.a + 3;
b) D p.a = new D( ) + 3;
c) D p = new( ); a = a + 3;
d) D p = new D( ); a.p = a.p + 3;
e) D p.a = new(int) + 3

6 Years
Discussion Span
Last Post by gangster88
Featured Replies

1st one is 'e'? and 2nd is 'a'? if i am right for the frist and second ones.. is it coz its a string for the 1st one (X is a string) so r.X wont make sense??

second one i dont knw and that is the only one.. i can see which seems valid.. but i am not sure about why the rest wont work? please help..



First question you got right. Indeed you cannot assign a numeric value to a String like that.
Second you got wrong. Look at the access modifier of the field. It's private, that means you can't assign to it from outside the class itself.
In fact, none of the statements given as possible answers there are correct.


what do u mean when you say outside the class?.. Is it before you close the "}" bracket, cause it is still inside the class right?


ok.. thx.. one lat quetion.. what are are the instances and attribute in this? or an example plz..

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.