Question: 1. Why sometimes we need to pass an array to a method? Use an JAVA code to show how to pass an array to a
1. Why sometimes we need to pass an array to a method? Use an JAVA code to show how to pass an array to a method.
2. What are the differences between array and arraylist in JAVA. What are the advantages of using arraylist?
3. If we want to copy an array, why can't we use the code below? How to correct it?
import java.util.Arrays; public class CopyAnArray { public static void main(String[] args){ int[] x = {1, 2, 3, 4, 5}; int[] y = x; }}
4. Is the code below correct? Why or why not?
class Vehicle { public void move(){ System.out.println(Vehicles can move!!); }} class MotorBike extends Vehicle { public void repair(){}} class Test{ public static void main(String[] args){ Vehicle vh=new MotorBike(); vh.move(); vh.repair(); }}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
