• Post Reply Bookmark Topic Watch Topic
  • New Topic

Test your basic concepts ....  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Default {
private int pri = 5 ;
protected int pro = 6 ;
public int pub = 7 ;
int def = 8;
}

public class Public {
private int pri = 1 ;
protected int pro = 2;
public int pub = 3;
int def = 4;
}

class Test1 extends Public {}

1] Test1 class can acess pro , def , pub variable with Test1 reference ( that is poining to Test1 object only ) , if it is in same package with Public

2] Test1 class can acess pro , pub variable with Test1 reference ( that is poining to Test1 object only ) , if it is not in same package with Public

3] Test1 class can acess pro , def , pub variable with Public reference ( that is poining to Public object only ) , if it is in same package with Public

4] Test1 class can acess pub variable with Public reference ( that is poining to Public object only ) , if it is not in same package with Public


class Test2 extends Default {}


5] Test2 class can acess pro , def , pub variable with Test2 reference ( that is poining to Test2 object only ) , if it is in same package with Default .

6] Test2 class can't even extends Default class , if it is not in same package with Default .

7] Test2 class can acess pro , def , pub variable with Default reference ( that is poining to Default object only ) , even if it is not in same package with Default .


How many statements out of seven are correct ...

[ January 06, 2005: Message edited by: rathi ji ]

[ January 06, 2005: Message edited by: rathi ji ]
[ January 06, 2005: Message edited by: rathi ji ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a thinly-veiled attempt to get us to do your homework?
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No paul ,
I just want answer & I dont want explanation .

according to me , all the points are correct . please let me know if i am wrong .

thank you very much .
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rathi, I think you will learn better by asking the compiler - try these things yourself and play with the variations. If you get a result you can't understand, we'll be glad to go over it.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i understand that it will help myself only but as you know that time is very less for beta ...
any expert can have a look & easily tell the answer .

don't explain answer if you also have less time but atleast mention the right answer .

thank you very much .
 
durga kar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the answers are correct but 7 is not I feel as I dont think you can access a default in other packages
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes durga ,

i am agree with you . although it was by mistake .

thank you very much .

durga please have a look on this also ... thanks .

question
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!