7. There is a class in the java API called vector. The objects in this class are
ID: 3823102 • Letter: 7
Question
7. There is a class in the java API called vector. The objects in this class are similar to an arraylist... see pictures. C++ only please! Do number 6 and 7 please!! T Normal No Spac... Heading 1 Heading 2 Paragraph 6. [4 points, 2 points each for a) and b) The URL class is used to allow Java to access websites. a. Write the import statement that is needed to use the URL class. import iava net HttpURLConnection; import java.net.URL; import Grading note: Could be import java.net. too-but it's not as nice. b. create a URL object and write the file name, path name, port number, and protocol name for that URL. 7. (10 points There is a class in the Java API called vector. The objects in this class are similar to an ArrayList, except for a detail that is irrelevant to this discussion. Suppose that methods with the following signatures were in the class. Should they be class methods or instance methods? a) add(int item) Add item to this Vector. b) add(int item, Vector v) Add item to Vector v. c) ector v Place the elements in Vector v in ascending order. d) sort0 Place the elements of this Vector in ascending order. e) binary int target) Search the elements of this Vector for the target value.Explanation / Answer
6.
a) Import statement for URL class
import java.net.URL;
URL class is availabel in the java.net package
b)
//Constructor
URL url=URL(String protocol, String host, int port, String file)
Creates a URL object from the specified protocol, host, port number, and file.
//example URL class object to create a url object
URL url=URL("https", "www.google.com", 80, "/index.html");
7)
Difference between instance method and class method.
The instance method is called using the object of the class.
The class method is a static method that can be called using class name itself
without using the object of class.
a) add(int item)
Type of Method : instance method
Since this method add elements to the class Vector data member.
b) add(int item,Vector v)
Type of Method : class method
Since the Vector class object is passed as parameter. So no need of
class object.
c) sort(Vector v)
Type of Method : class method
Since the Vector class object is passed as parameter. So no need of
class object.
d) sort()
Type of Method : instance method
sort applies on the data members of the Vector class
e)binarySearch(int target)
Type of Method : instance method
The method binarySearch that takes integer number as target
and finds the target in the vector object.So, object is required.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.