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

no, YOU tell US what you think, and we may tell you if you're right.

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

thx

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?

read up on what private means and you should understand.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.