• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Certification cx 310-035

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot
 
reply
    Bookmark Topic Watch Topic
  • New Topic