File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes few queries with the program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "few queries with the program" Watch "few queries with the program" New topic
Author

few queries with the program

satya narayan reddy
Greenhorn

Joined: Nov 26, 2005
Posts: 13
import java.util.*;
public class Vector
{
/*public Vectors(int x,int y)
{
System.out.println("in the vector constructor");
}*/
public Vector()
{
System.out.println("in the empty constructor");
}
public Vector(int x ,int y)
{
System.out.println("in the vector constructor");
}
public Vector(int z)
{
System.out.println("in the vector with storage capacity");
}
public boolean addElement(Object obj)
{
System.out.println("added into the vector");
return true;
}
public final int capacity()
{
System.out.println("capacity of the constructor");
return 6 ;
}
public final boolean contains(Object obj)
{
System.out.println("in the contains method");
return true;
}
public static void main(String args[])
{
Vector v = new Vector(5,1);
System.out.println("" +v);
Vector w = new Vector(3);//capacity is 3 but still taking velagala>3
System.out.println("" +w);
Vector x = new Vector();
System.out.println("" +x);
boolean c=x.addElement("venkat");
System.out.println("" +c);
boolean d = w.addElement("velagala");
System.out.println("" +d);
System.out.println("" +w.capacity());//y this is not returning the capacity
//of the vector
boolean f=x.contains("simha");//y this is method is returning true when there is no simha in the vector collection named x
System.out.println("" +f);
}
}

hi all,
i have few queries with the above program.
can anyone try to fix the problems which i placed in the comments

thanks,
satya
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

There is already a class Vector in the package java.util that you're importing. You should not call your own class "Vector". Use a different name, otherwise the compiler doesn't know if it should use your class Vector or the class Vector in package java.util.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
System.out.println("" +w.capacity());//y this is not returning the capacity
//of the vector

Because you have hard coded it to return 6

boolean f=x.contains("simha");//y this is method is returning true when there is no simha in the vector collection named x

Because you have hard coded it to return true.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: few queries with the program
 
Similar Threads
program needs to be explained
Declare and use interface
Array Confsion
Help with adding elements to vector
Multithreading: bouncing balls problem