Can a class implement more than one interface?
Yes.
Can interfaces have constructors?
No.
How do you find the length of an array?
varName.length
How do you find the length of an arraylist?
varName.size()
interface A
{
private int add(int a, int b);
}
Is anything wrong in the above code? If so, what?
Methods have to be public in an interface.
interface MyInterface
{
void myMethod();
}
class MyClass implements MyInterface
{
public void myMethod()
{
return ;
}
public static void main(String[] args)
{
MyInterface sample = new MyClass();
}
}
Is anything wrong in the above code? If so, what?
It is right.
How do you create an integer array with 5 elements and variable name "nums"?
int[] nums = new int[5];
How do you create an arraylist of integers with variable name "nums"?
ArrayList<Integer> nums = new ArrayList<Integer>();
All members of interface are public by default. True or false?
True
interface MyInterface
{
void myMethod();
}
MyInterface sample = new MyInterface();
Is anything wrong in the above code? If so, what?
Cannot create instances of interface type. Only of classes that implement the interface.
How do you create a 2d array of integers with 3 rows and 4 columns and variable name "nums"?
int[][] nums = new int[3][4];
How do you add the number '5' to an ArrayList "nums"?
nums.add(5);
How do you access the integer at second row and third column of the 2d integer array "nums"?
nums[1][2]
How do you access the 5th index value of an ArrayList of integers "nums"?
nums.get(5);