• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

few queries with the program

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic