·
Two public classes in the same file.
Ans: public class All{public class Test1 { }public class Test2 { }}
·
Main method calling a non-static method.
Ans: Class A(){public String call(){……….};}
Class B{public static void main(String[] args) { A a1= new A(); a1.call();}}
·
Methods with the same name as the constructor(s).
Ans : Yes
public class All {All(){System.out.println("Constructor");}
public String All(){System.out.println("Method");return "none";}
public static void main(String args[]){All a=new All();a.All();}
·
If no user defined
constructor is provided for a class, compiler initializes member variables to
its default values.
Ans: numeric
data types are set to 0
char data types are set to null character(‘’)
reference variables are set to null.
·
In order to create a
Constructor follow the rules
Ans: It has the same name as the class
It should not
return a value not even void
·
Thread initiation with classes that don’t have a run ()
method.
Ans:
public class All extends Thread{
public void run() /* It
calls super.run() if no run implementation if extends thread class */
{System.out.println("Run method
is not mandatory and optional if class extends Thread class");}
public static void main(String
args[]){All a= new All();a.start();}
public class All implements Runnable{
public void run(){
System.out.println("Run implementation
is mandatory if class Implements Runnable Interface");
}
public static void main(String
args[]){All a= new All();Thread t= new Thread(a);t.start();}
·
Difference Between Run and Start methods in Threading
Ans:
The start () method
creates a new thread, that executes the run() method.
The run () method just
executes in the current thread, without starting a new thread.
Remaining questions will be updated shortly......
No comments:
Post a Comment