Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions java interview question
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kalyan ram mannem
java interview question
1 Answer(s)      3 years and 10 months ago
Posted in : Java Interview Questions


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?

Advertisement
View Answers

January 31, 2011 at 3:51 PM


Hi Friend,

Try this:

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:
java interview question and answer - Java Interview Questions
java interview question and answer   sir, i want one mark java interview question and answers
Interview question link - Java Beginners
Interview question link  Hi, I want JAVA+J2EE interview question and answer please suggesion me link
Advertisements
Java Interview Question
Java 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
Core Java Interview Question, Interview Question
Core Java Interview Question   ....   Core Java Interview Question Page 1 How could Java... to a file?      Core Java Interview Question Page 2
interview question - Java Interview Questions
interview 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
java interview question
java interview question  what is the usage of abstract class
java interview question
java interview question  when will we use abstraction or interface
Interview Question - Java Interview Questions
Interview Question  I need Interview Questions on Java,J2EE Pls help me
Interview question - Java Interview Questions
Interview 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 Questions
Interview question   Hi Friends, Give me details abt synchronization in interview point of view. I mean ow to explain short and neat. Thanks
Core Java Interview Question, Interview Question
Core Java Interview Question Page 14       Question: What is clipping? Answer: Clipping... that is implemented in a language other than Java. Question: Can a for statement loop
Core Java Interview Question, Interview Question
Core Java Interview Question Page 21       Question: How are the elements of a GridLayout... and are laid out using the squares of a grid. Question: What an I/O filter? Answer: An I
Core Java Interview Question, Interview Question
Core Java Interview Question Page 17       Question: What is the difference between... application window that can have a menu bar. Question: Which class is extended by all
Core Java Interview Question, Interview Question
Core Java Interview Question Page 22       Question: What is a compilation unit? Answer: A compilation unit is a Java source code file. Question: What interface
Core Java Interview Question, Interview Question
Core Java Interview Question Page 23       Question: To what value is a variable... and interfaces that are loaded by a Java program. Question: How does a try statement
Interview Question - Java Interview Questions
Interview 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 27       Modifiers Question: What are access modifiers... written in non java language Question: What are transient variables
Core Java Interview Question, Interview Question
Core Java Interview Question Page 18       Question: Is &&= a valid Java operator? Answer: No, it is not. Question: Name the eight primitive 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... mentions a shallow copy in Java? Answer: Object cloning. Question: If you're
Core Java Interview Question, Interview Question
Core Java Interview Question Page 26       Language Fundamentals Question: How... 64 - - Question: What types
Core Java Interview Question, Interview Question
Core Java Interview Question Page 16  ... implementation is deferred to a subclass. Question: How are Java source code files... and interfaces. Source code files use the .java extension. Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 12       Question: What is a transient variable? Answer... collections of objects. Question: How does Java handle integer overflows
Core Java Interview Question, Interview Question
Core Java Interview Question Page 15  ... is to provide access to the Java runtime system. Question: How many times may... takes an argument of the String[] type. Question: Which Java operator is right
Core Java Interview Question, Interview Question
Core Java Interview Question Page 32   ... Question: What is the ultimate ancestor of all java classes Answer: Object class is the ancestor of all the java classes Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 13       Question: What is an Iterator interface? Answer.... Question: What is the difference between the >> and >>> operators
Core Java Interview Question, Interview Question
Core Java Interview Question Page 30       Objects and Classes Question: What's... while regular methods could be called many times. Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 19       Question: What is the difference between static... variables take on unique values with each object instance. Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 20       Question: Name four Container classes. Answer: Window, Frame, Dialog, File Dialog, Panel, Applet, or ScrollPane Question: What
Core Java Interview Question, Interview Question
Core Java Interview Question Page 25  ... be called. Question: Does java support virtual functions Answer: No java... Question: What is JVM Answer: When we install a java package
Core Java Interview Question, Interview Question
Core Java Interview Question Page 24       Question: Why do we need public static void main.... Question: What is reflection in java Answer: Reflection allows Java code
Core Java Interview Question, Interview Question
Core Java Interview Question Page 11       Question: What is serialization ?  Answer: Serialization is the process of writing complete state of java object
 

 

 

DMCA.com