a) main method b) finalize method c) static method d) private method Answer: ...
View Question
What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
int arr[] = {1, 2, 3, 4, 5};
for ( int i = 0; i < arr.length – 2; ++i)
System.out.println(arr[i] + ” “);
}
}
What will be the output of the following Java program? class Output ...
View Question
What will be the output of the following Java program?
class static_out
{
static int x;
static int y;
void add(int a , int b)
{
x = a + b;
y = x + b;
}
}
class static_use
{
public static void main(String args[])
{
static_out obj1 = new static_out();
static_out obj2 = new static_out();
int a = 2;
obj1.add(a, a + 1);
obj2.add(5, a);
System.out.println(obj1.x + ” ” + obj2.y);
}
}
What will be the output of the following Java program? class static_out ...
View Question
What will be the output of the following Java program?
class access
{
static int x;
void increment()
{
x++;
}
}
class static_use
{
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.increment();
obj2.increment();
System.out.println(obj1.x + ” ” + obj2.x);
}
}
What will be the output of the following Java program? class access ...
View Question
What will be the output of the following Java program?
class access
{
public int x;
static int y;
void cal(int a, int b)
{
x += a ;
y += b;
}
}
class static_specifier
{
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.y = 0;
obj1.cal(1, 2);
obj2.x = 0;
obj2.cal(2, 3);
System.out.println(obj1.x + ” ” + obj2.y);
}
}
What will be the output of the following Java program? class access ...
View QuestionWhich of these methods must be made static?
a) main() b) delete() c) run() d) finalize() Answer: a Explanation: ...
View QuestionWhich of the following statements are incorrect?
a) Variables declared as final occupy memory b) final variable must be initialized at the ...
View QuestionWhich of the following statements are incorrect?
a) static methods can call other static methods only b) static methods must only access static data c) static ...
View QuestionWhich of these cannot be declared static?
a) class b) object c) variable d) method Answer: b Explanation: static statements are run as soon as class ...
View QuestionWhich of these keywords is used to prevent content of a variable from being modified?
a) final b) last c) constant d) static Answer: a Explanation: A variable can be declared final, ...
View Question