• 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

this keyword and JQPlus Qs

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Tualha Khan
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, the semicolon ';' is converted to a smiley!!

Bye,
Tualha Khan
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your answer for GridLayout is fine. Java is not space sensitive.
 
Tualha Khan
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic