java interview question
class Test
{
void meth1()
{
System.out.println("meth1()");
meth2();
}
static void meth2()
{
System.out.println("meth2()");
}
public static void main(String[] args)
{
Test t=new Test();
t.meth1();
}
}
query: In the above program in meth1() the static method method2() is called.
How meth2() is called?with object reference((t)(this))) or with class name(Test)?
When i tried to print this (System.out.println(this);) inside meth2() it is giving error
non static variable this can't be referenced from static context.
what i know : To call a non static method from a non static method no need of any
object reference.we can directly call. The calling method uses this and calls.
In case of calling static method from static , we can directly
call(here class name will be used) or we can use object reference.
when calling static method from non static method,there are again
two chances only,calling with object reference(this) or class name.
If it uses current object( this ) it should allow to print this inside that class na?
View Answers
January 31, 2011 at 3:51 PM
Hi Friend,
Try the following code:
class Test {
void meth1() {
System.out.println("meth1()");
meth2();
}
static void meth2()
{
System.out.println("meth2()");
}
public static void main(String[] args)
{
Test t=new Test();
t.meth1();
meth2();
}
}
Thanks
Related Tutorials/Questions & Answers:
Advertisements
Java Interview QuestionJava Interview Question
Java program
Interview Question :i have a file which contains characters and integers in mixed format.
for example :-->
abd12 g156bcd etc
Now how would i rearrange the file sothat the characters
interview question - Java Interview Questionsinterview question hello i want technical
interview question in current year
Hi Friend,
Please visit the following links:
http://www.roseindia.net/interviewquestions/
http://www.roseindia.net
Interview question - Java Interview QuestionsInterview question
Hi Friends,
I am new to
java, can u tell me what is class ,object and instance with example. For example : class raja , raja r = new raja(); ,here raja is class and r is instance
Interview Question - Java Interview QuestionsInterview Question 1)If we give S.O.P. statement after finally block shall it prints or not?
2)Write a program in
java to read a file & write in to another file?
3)Write a program taking two arrays and compare those two
Core Java Interview Question, Interview Question
Core
Java Interview Question Page 16
..._TO_REPLACE_3
Question: How are
Java source code files named?
Answer: A
Java source code... the .
java extension. ADS_TO_REPLACE_4
Question: What is the relationship between
Core Java Interview Question, Interview Question
Core
Java Interview Question Page 15
... to the
Java runtime system.
Question:
How many times may an object's finalize...: A program's main() method takes an argument of the String[] type.
Question: Which
Java Core Java Interview Question, Interview Question
Core
Java Interview Question Page 2
....
Question: What
comes to mind when you hear about a young generation in
Java...
Question: How would you make a copy of an entire
Java object with its state
Core Java Interview Question, Interview Question
Core
Java Interview Question Page 23
... group. ADS_TO_REPLACE_3
Question: What is a
Java package and how is it used... that are loaded by a
Java program. ADS_TO_REPLACE_5
Question: How does a try statement
Core Java Interview Question, Interview Question
Core
Java Interview Question Page 24
....
Question: What is reflection in
java
Answer:
Reflection allows
Java code..., it is read only
Question: What is the difference between
Java Bean and
Java Core Java Interview Question, Interview Question
Core
Java Interview Question Page 25
... function would be called.
Question: Does
java support virtual functions.... A
Java program requires a JVM to run on a particular platform
Question: Can
java interview questionjava interview question class Test
{
void meth1()
{
System.out.println("meth1()");
meth2();
}
static void meth2()
{
System.out.println("meth2()");
}
public static void main
java interview questionjava interview question class Test
{
void meth1()
{
System.out.println("meth1()");
meth2();
}
static void meth2()
{
System.out.println("meth2()");
}
public static void main
Important Java Interview QuestionImportant
Java Interview Question Complete the Solver constructor so that a call to solveAll return a list with 2 values including the square root and the inverse of the integer passed as parameter.
public interface
Java interview questionJava interview question Hello i had an online test in some company and i didn't succeed in doing it(they gave me a timeline) this was the test... and said to do it in
Java(Regular
java programming),but I didn't
know how
core java question - Java Interview Questionscore
java question I Have been asked the
question in
interview
why we use constructors?????
or
what is the need of constructors??
or
what is the utility of constructors???? to intialize the instance variabe we
Spring question - Java Interview QuestionsSpring question Hi
Pls any one give idea abot this
question?
in the above statement, what is the meaning og abstarct = true?
Thanks In Advance
Hi friend,
Read for more information.
http
Interview question.Interview question. Program to read the integers from the standard input (until it gets a negative number) and puts them in to an array.after that it calls process Array on the array,and then prints the content of the array