Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Certification cx 310-035

 
Thomas Thomas
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two questions. One i need a comments and second i need an answer.
public class Test{
static int var1=5;
public void increment(int var1){
var1= var1+this.var1;
System.out.println(var1);
}
public static void main(String[] args){
Test A = new Test();
A.increment(2);
}
}
I need a comment that with "this" reference answer is different as you all know. I am working on a static with "this" combination which sounds bad..
The second one is i am following kathys book for programmer certification ..Good one. I will say more after the exam.
package cert;
class Beverage{
}
package exam.stuff;
import cert.Beverage;
class Tea extends Beverage{
}
The question that Kathy asked was
?What do you best suggest as a access modifier for class Beverage.
Ans:Either make the class Beverage public or put both them in same package. In an Earlier instance she mentioned private and protected are not useful modifiers for the class. I could figure out "private". But why not protected in the above case?
Thanks for Effort
Thomas
 
Edwin Keeton
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Addressing your 2nd question, a top-level class can only have default or public access. A private class would clearly be meaningless and is not allowed.
The protected keyword refers to visibility through inheritance rather than by reference. It applies to members rather than classes because you don't inherit a super class but rather the members of a super class. So protected is also not allowable as an access modifier for top-level classes.
If you could have a protected class, it would not be visible outside its package anyway, and would not be distinguishable from default access.
 
Kao-Wei Wan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Test{
static int var1=5;
public static void increment(int var1){
var1= var1+Test.var1;
System.out.println(var1);
}
public static void main(String[] args){
Test.increment(2);
}
}
how about this??
 
Thomas Thomas
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic