ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories >> Software >> Java-Related
 
  J2ME (99)  Java-Related-AllOther (21)
 


 

Back to Questions Page
 
Question
can a static method be overridden
Rank Answer Posted By  
 Question Submitted By :: Ravi
This Interview Question Asked @   SolutionNET
I also faced this Question!!   © ALL Interview .com
Answer
any one reply the answer with ex
 
0
Ravi
 
 
Answer
Static method will be represented by class, not by objects.
Overriding technique will be for objects; Even if we have 
same method in the sub class also that will be a static 
method for that class
 
0
Rama Devi
 
 
Answer
Hi rama devi,u are written the answer is ok but not clear
i given one example of this 

what i am saying is the static methods are not overriden 
cause the class loader will load the while loading the 
class at runtime so the compiler will check the which 
static method would i need to call co its confused thas's 
why the static methods are not overriden.

EXAMPLE:

class A {
static void something () {}
}

class B extends A {
static void something () {}
}

....
A anA = new B ();
anA.something (); 

think and compile what's the comipler say's.
 
0
Narasimha Rao Bodagala
 
 
 
Answer
Hi, Narasimha Rao Bodagala
I didnt get u. can u please explain once?
 
0
Sandya
 
 
Answer
static method can be overridden
 
0
Gaythri
 
 
Answer
public class Test extends Test2{

public static void main(String args[]){
	String str="";
	int b=Test.cal(4);
	System.out.println(b);
	Test t =new Test();
	t.displayX();
}

 public static int cal(int a){
	 int b=a*a;
	 return b;
 }
 
}

public class Test2 {
	public static void main(String args[]){
		
	}

	public static int cal(int a,int b){
		 int c=a*b;
		 System.out.println("IN Super orerriden 
methods:");
		 return c;
	 }
	
	public void displayX(){
		System.out.println("HI i am in Super");
	}
	
}
my Sub Class is Test extends Test2 Class
Common static method is cal()

its run properly. No compile error , NO runtime error
 
0
Aswini De
 
 
Answer
Hi, Aswini ur program is wrong, there is no relation btween 
cal methods in ur program, overriding means there must be 
same no of arguments,there is a change in no of argumetns 
in ur program.
static methods can not be overridden
ex:
  main method is static, we can overload it but we can not 
override it.
 
0
Srinivas Katta
 
 
Answer
Hi, Srinivas.....in the above program posted by Aswini...I 
think main() method is overridden....right?.....then we can 
say static methods can be overridden....

Eg:

class Parent
{
    public static void myStaticMethod()
    {
        System.out.println("A");
    }

    public void myInstanceMethod()
    {
        System.out.println("B");
    }
}

public class Child extends Parent
{
    public static void myStaticMethod()
    {
        System.out.println("C");
    }

    public void myInstanceMethod()
    {
        System.out.println("D");
    }

    public static void main(String[] args)
    {
        Parent o1 = new Parent();

        Child  o3 = new Child();

        Parent.myStaticMethod();  // A
        Child.myStaticMethod();   // C

        o1.myStaticMethod();      // A
        o1.myInstanceMethod();    // B


        o3.myStaticMethod();      // C
        o3.myInstanceMethod();    // D


    }
}

In the above program myStaticMethod() is 
overridden.....which is a static method.....
 
0
Karteek
 
 
Answer
Static methods CANNOT be overridden as they belong to a
class and not an instance of the class. 

Aswini De: First of all, you didnot override the cal method.

Karteek: In your example, the fact that
parent.mystaticMethod and child.mystaticmethod are printing
different answers is in itslef an indication that the method
is not overridden!!

-kk
 
0
Kiran Kadarla
 
 
Answer
An instance method can not override the static method of 
its parent class.like
if parenet class contains
public static void test()
{
}
then in child class you can't override like this

public void test(){ //you can't override
}
or even like this

public static int test(){  //compile time error:type is 
incompatibe with parent's test method.
}
 
0
Abid Mehmood
 
 
Answer
only static method in a subclass can over ride the static
method in the parent class.

for example

public class A {
 public static int display(){
	 System.out.println("i an in A");
	 return 1;
 }

}


public class B extends A{
	
	 public static int display(){
		
		 System.out.println("i an in B");
	 	 return 1;
	 	 }
	 
	
	 /*public int display(){
		 
	 }*/
}

will work fine. but if the subclass tries to override parent
class static method with a non static method it generates
compilation error.

for eg

public class B extends A{
	
	/* public static int display(){
		
		 System.out.println("i an in B");
	 	 return 1;
	 	 }*/
	 
	
	public int display(){
		 
	 }
}
the above code will result in compilation error.
 
0
Mayank
 
 
Answer
@ Mayank

Static methods are *NEVER* ever be overridden, even if you
try to override a static method of the super class in your
subclass, it will compile because in this you are simply
redeclaring the static method of your superclass in your
subclass. Redeclaring a method is not the same as overriding
a method.

The bottomline is 

** STATIC METHODS CAN NEVER BE OVERRIDDEN **
 
0
Partha
 
 
Answer
yes main method can be override example

class mad
{
public static void main(String args[])
{}
}
public class mohit extends
{
public static void main(String args[])
{
System.out.println("HELLO");
}}


output HELLO
ANY question contact me with our email.my id.
mohit_kaushik1234@rediff.com
 
0
Mohit Kaushik
 
 
Answer
Static methods are not overriden, they are hidden by static
method in subclass. Check out the link: 

http://www.xyzws.com/javafaq/can-static-methods-be-overridden/1
 
0
Nitasha
 
 
Answer
static method can be overriden. that is true
 
0
Mohit
 
 
Answer
* STATIC METHODS CANT BE OVERRRIDDEN....*

class Animal {
   static void doStuff() {
       System.out.print("a ");
   }
}

class Dog extends Animal {
     static void dostuff() { // it's a redefinition,
                 // not an override
           System.out.print("d ");
        }

public static void main(String [] args) {
    Animal [] a = {new Animal(), new Dog(), new Animal()};
    for(int x = 0; x < a.length; x++)
          a[x].doStuff(); // invoke the static method
}
}

Running this code produces the output:
a a a
 
0
Let The Code Speaks....
 
 
Question
diff vector arraylist
Rank Answer Posted By  
 Question Submitted By :: Ravi
This Interview Question Asked @   Saka-Solutions
I also faced this Question!!   © ALL Interview .com
Answer
1) Arraylist is not synchronised while vector is 
synchronised.

2) ArrayList doesn’t have a constructor for specifying the 
incremental capacity, where as Vector has a constructor to 
specify the initial capacity and incremental capacity. 

3) Vector is serialized but arraylist is not.
 
0
Chandra
 
 
Answer
Both classes are serializable.See the java doc for 
clarification. 
Please dont misguide readers
 
0
Lipu
 
 
Question
whether the connectionpooling used in struts?
Rank Answer Posted By  
 Question Submitted By :: Ravi
This Interview Question Asked @   SolutionNET
I also faced this Question!!   © ALL Interview .com
Answer
Connection polling is nothing but , group of database 
connection whichs are maintain and reuse and if no loger 
use the remove, is a technique , connection polling 
technique release in JDBC 2.0 - optional package, another 
Optional API is data base connection using JNDI, instead of 
DriverManager
 
0
Aswini De
 
 
Question
how the mapping can be done from jsp to actionservlet?
Rank Answer Posted By  
 Question Submitted By :: Ravi
This Interview Question Asked @   SolutionNET
I also faced this Question!!   © ALL Interview .com
Answer
Through config file 

in Struts we have to load the frmework config file
struts-config.xml
in this file we have to configure the particular jsp to 
land the request on action servlet, default ActionServlet 
is unique in struts framework
 
0
Satya
 
 
Question
explain the flow of struts?
Rank Answer Posted By  
 Question Submitted By :: Ravi
This Interview Question Asked @   SolutionNET
I also faced this Question!!   © ALL Interview .com
Answer
a)Client makes a Http Request.
b)Every request has to go to the ActionServlet which 
actually is the Front Controller of Struts.
c)ActionServlet calls the Request Processor for execution 
of the request.
d)Request Processor reads the xml file (Struts-config.xml) 
where the mappings have been provided for each and every 
request and finds out the corresponding Action Class 
mapping to that request.
      (1)How the mappings are provided in Struts-Config.xml 
file will be discussed under Configuring Recipe Module.
e)Before passing the control to the execute() method of the 
Action Class, it instantiates the Form Bean associated with 
that Action Class.
f)Once the Action Form/ Form Bean is instantiated, control 
goes to execute() method of Action Class.
g)Action Class then call the Business Layers to fetch the 
data requested by the client.
h)Once the data is fetched, it is populated in the Form 
Bean and control goes back to Action Class.
i)And finally, Action Class throws the control to JSP page 
where the data is rendered.
j)To render the data on JSP page, data is taken out of Form 
Bean with the help of Struts Tags.
k)Struts provides us with various Tag Libraries which makes 
the JSP page easy to create and maintain.
l)JSP Tags will be discussed later. 

 
3
Kumar S
 
 
Answer
Answer is correct,Need some explanation along with examples 
for configuration xml and all.
 
0
Pavankumar
 
 
Question
diff between jsp include directive and jsp action include?
Rank Answer Posted By  
 Question Submitted By :: Ravi
This Interview Question Asked @   SolutionNET
I also faced this Question!!   © ALL Interview .com
Answer
jsp include directive --its cal at d translation time,
jsp action include---its cal at runtime
 
3
Soori
 
 
Answer
diff between jsp include directive and jsp action include:
1)syntax of inclde directive<%@ include file="filename"%>
  syntax of inclde action<jsp:include page="filename">
2)inclde directive : done when compilation time
  inclde action: done when requestprocessing time
3)inclde directive: included content is static
  inclde action:included content is static or dyanamic
 
0
Bhudeep
 
 
Question
difference between applicationserver and webserver
Rank Answer Posted By  
 Question Submitted By :: Ravi
This Interview Question Asked @   SolutionNET
I also faced this Question!!   © ALL Interview .com
Answer
web server allows only HTTP protocal(i.e Protocal dependent)
But App Server Protocal independent
web server is less secure than app sever
 
0
Venkat
 
 
Answer
Web Server is used to render mostly static content (html
pages), while app server is capable of offering more
services like execution of dynamic pages (jsp,servlets) and
offeres many out of box infrastructure components like
security, transaction handling, database connectivity, and
many other services.

WebServer and Appservers can be on different boxes to
improve performance in Ntier architecture.
 
0
Veeru
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com