aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes this keyword and JQPlus Qs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "this keyword and JQPlus Qs" Watch "this keyword and JQPlus Qs" New topic
Author

this keyword and JQPlus Qs

Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
Dear All,
Hey,
I am not able to understand the usage of keyword 'this'. Can somebody suggest a link or explain me in a very detailed manner about the functionality of the keyword 'this'.
Bye,
Tualha Khan

From JQPlus
Question ID :953836219840
Write a line of code that declares a variable named 'layout' of subclass of class LayoutManager and initializes it with a new object, which when used with a container can lay out components in a rectangular grid having 2 columns and 4 rows.
(Use space only where necessary)
My Answer (as exactly typed in the filling area):
GridLayout layout=new GridLayout(4, 2);
(Notice the line terminator ( in the end)
Answers Suggested by the Software:
GridLayout layout = new GridLayout(4, 2); //spaces between layout = new
LayoutManager layout=new GridLayout(4, 2);
LayoutManager layout=new GridLayout(4,2); //space between 4 and 2 is removed
LayoutManager layout=new GridLayout(4,2); //Exactly as Above
GridLayout layout=new GridLayout(4,2) //no space in 4,2 and no line terminator (
Is my answer wrong? I have not used any quotes, just the spaces I thought to be fit. Somebody (maybe moderators) solve the confusion relating to fill in the blank type of questions.
Bye,
Tualha Khan


SCJP2, BEA WLS 6.0, DB2 UDB 7.1
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
Sorry, the semicolon ';' is converted to a smiley!!

Bye,
Tualha Khan
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
The this keyword has 2 definitions:
this: It is a keyword that is a reference variable that points to
the current object.
this: can also be used in a constructor to mean a constructor in
this class that has the same parameters.
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Your answer for GridLayout is fine. Java is not space sensitive.
Tualha Khan
Ranch Hand

Joined: Nov 22, 2000
Posts: 287
Java as a programmer's language being space insensitive is not the problem here.
The problem here is how to answer the question in fill in the blank type. I know the answer is right, but still the software rejected it, in case the same happens in the real exam, then things will become absolutely different. After all, it's one whole question which could either fetch me a certificate or deny me one. People who have already appeared in the real exam, please guide me!!!
Bye,
Tualha Khan
Anshuman Acharya
Ranch Hand

Joined: Jan 19, 2001
Posts: 144
regd this:
we know that "this" is implicitly placed by the compiler within a method of a class whenever another method/variable of the class is called, like -
//code
class a{
int a;
void b(){};
void c(){
int a1 = a;//a read as this.a
b();//read as this.b()
}
}
//code ends
but in some situation you need to pass the current instance as the parameter to some method and then you may need to use "this" explicitly, like
//code
class a implemnts Runnable{
public void run(){}
public static void main (String arg[]){
Thread t = new Thread(this);//note!
t.start();
}
}
//code ends
got it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: this keyword and JQPlus Qs