File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what could be the modifiers of this ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what could be the modifiers of this ?" Watch "what could be the modifiers of this ?" New topic

what could be the modifiers of this ?

Srivathsalachary Vangeepu

Joined: Nov 06, 2000
Posts: 1
1. "this" is a reference to current object and available to all methods, right ? what can be said about its modifiers ?
class Test {
public final Test this;
2.If we implement an abstract method of an interface in a class,
is it correct to say that we are overriding the method ?
3. Is constructor a member method or not ? Is it implicitly static ?
4. I remember reading in the site that "private means private to class but not private to objects. say Test class has a private
vbariable int x. If we instantiate two objects obj1 and obj2 of class Test,how can obj1 access obj2.x ? Looking for code snippet if it is possible.

thanks in advance.

Ayman Jaffar
Ranch Hand

Joined: Sep 06, 2000
Posts: 57
There's no such code as "public final Test this;" and if you compile it, the compiler will complane.
And it can't have a public, protected, private, nor friendly modifier, becuase all variables inside a method can't be declared with such modifiers. But "this" is final, becuase it can only be used to change the variable of an Object or to invoke that method of an Object but it can't point to a different Object (like saying this = new Cup () )
2- yes
3- Constructor is a member method, and I don't see why not.
No it's not static becuase there is a constructor for each
Object when it's created
public class Test {
private int x = 1;
void privateMethod (int x) {
System.out.println("t2.x is " + x + " and t1.x is " + this.x);
public static void main(String[] args) {
final Test t1 = new Test();
final Test t2 = new Test();
I recomend your read the Khalid and Rolf book, for the java certification, (it's at and but if you buy it at javaranch you'll help support this site) . I think you lack some basic information but you have to keep going on.
Good luck on the certification.

[This message has been edited by Ayman Jaffar (edited November 06, 2000).]

yogesh sood
Ranch Hand

Joined: Aug 31, 2000
Posts: 108

I will try to answer step by step.and also hope u will also do same
1) u a cannot give any access modifier to this
to learn more bout this read my previous reply on this topic

2)Yes u can say that u are overriding method same thing u do in case of abstract class .
3)Constructor is not member of class it is not inherited by Derived classes neither it is static.constructor can only be public, private, protected ;
4) read Following code
class Testc{
private int s;
public void set(int temp){s=temp;}
public int get(){return s;}

public static void main(String args[]){

Testc Q1=new Testc();
Testc Q2=new Testc();

System.out.println("Both Same");
System.out.println("Both Not Same");

boolean compare(Testc temp1)
if (temp1.s==this.s)
return true;
return false;


in above code we are creating two object of class Testc and passing them to compare method of third object where we r using
if (temp1.s==this.s)
mean object are accessing private varible of each other so private restication is only to class not to object if u write these statment in other class u will get error coz varible s of class Testc is not available outside class Testc
Hope this will Help
[This message has been edited by yogesh sood (edited November 06, 2000).]

If its green its biology if its stinkks its chemistry if it has numbers it is Maths and if it doesn't work its TECHNOLOGY
I agree. Here's the link:
subject: what could be the modifiers of this ?
It's not a secret anymore!