Methods
- What is the process of defining a method in subclass having same name & type signature as a method in its superclass?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Method overriding
- Which of these keyword can be used in subclass to call the constructor of superclass?
-
View Hint View Answer Discuss in Forum
None of these
Correct Option: D
super
- What is the output of this program?
class box_Shape
{
int w;
int h;
int l;
int vol;
void vol(int h, int l, int w)
{
vol = w * h * l;
}
}
public class Prameterized_method_Example
{
public static void main(String args[])
{
box_Shape obj = new box_Shape();
obj.h = 6;
obj.l = 3;
obj.w = 4;
obj.vol(6, 3, 4);
System.out.println(obj.vol);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Output: 72
- Which of these statement is incorrect?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Even if a method is returning a value, it is not necessary to store that value.
- What is the output of this program?
class method
{
int p;
int q;
void add(int n)
{
p = n + 2;
}
void add(int n, int b)
{
p = n + 5;
}
}
public class method_overloading
{
public static void main(String args[])
{
method obj = new method();
int n = 0;
obj.add(10);
System.out.println(obj.p);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Output: 12