1/34
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
This keyword is used when a method is NOT allowed to be overriden by a subclass.
final
Which of the following access modifiers is the least restrictive?
public
Which of the following statements is NOT TRUE?
A static method can access an intance method.
Which package modifier is the most restrictive?
private
Which of the following keywords indicates that the method will NOT return a value?
void
Which modifier allows access to the subclass of the class?
protected
Which of the following is optional in a method declaration?
Access modifier
These are the variables listed in a method declaration.
Parameters
This keyword is used when a method DOES NOT have a body.
abstract
This occurs when a primitive type is instantly converted to its object wrapper class.
Autoboxing
It consists of the method’s name and parameter types.
Signature
This method belongs to the class rather than the object of a class.
Static Method
What occurs when a method has the same name with another method but has a different parameter types?
Overloading
These are the actual values that are passed in when a method is invoked.
Arguments
Which modifier grants access only to members of its own class?
private
What is the output of the code below?
public class Apple {
static String color = “red”;
Apple apple = new Apple();
apple.color = “green”;
System.out.println(apple.color);
}
}
green
What is the output of the colde below?
public class Test {
private static void add(int i, int j) {
System.out.println(“int”);
}
private static void add(Integer i, Integer j) {
System.out.println(“Integer”);
}
public static void main(String[] args) {
add(10, 20);
}
}
int
What is the result of the code below?
public class HowMany {
public int add(int one, int two){
return one + two;
}
public static void main(String[] args) {
HowMany h = new HowMany();
int result = h.add(2, 3);
System.out.println(result);
}
5
Which of the following will compile succesfully?
final static void methodA() { }
Which of the following method declaration is correct?
boolean isCorrect() {
return true;
}
Which line leads to compilation error?
public class Prelim {
System.out.println(count);
}
public static void main(String[]args){
Prelim.displayMsg();
}
}
System.out.println(count);
What is true in the following statement?
student.report(course);
report is the method name.
What is the result of the code below?
public class Test {
private static void add(Double i, Double j) {
System.out.println(“Double”);
}
private static void add(float i, float j) {
System.out.println(“float”);
}
public static void main(String[] args) {
add(5.0, 10.0);
}
}
Double
Which of the following will compile successfully?
public int methodC() { return 0; }
Which of the following is a valid method declaration in Java?
public int compute(int a, int b) { return a + b; }
Why will the code below NOT compile?
class Caller {
private void start() {
System.out.print(“Started”);
c.start();
}
}
The start() method is private.
What is the output of the code below?
public class Test {
static void m(int x) {
System.out.println(“int”);
}
static void m(char x) {
System.out.println(“char”);
}
public static void main(String [] args) {
int i = 5;
m(‘5’);
}
}
char
Which of the following can fit the missing statement?
public class Prelim {
____void method() { }
}
final
Which of the following statements declares a constant field?
final static int x = 10;
What is the result of the code below?
public class Test {
public String name;
public static void main(String [] args) {
Test obj = new Test();
System.out.println(obj.name);
}
}
null
In the method call calculateTotal(5, 10), what re 5 and 10 reffered to as?
Arguments
Which method header defines a method named convert that takes no parameters and returns an int?
int convert() { }
What will be the result if a method with non-void return type does not include a return statement?
The program will result in a compilation error.
What is true about instance methods?
They can access both static and instance variables.
Which of the following scenarios will result in a compilation error when declaring methods in the same class?
Two methods with the same name, same parameter list, but different return types.