Programming Final Review Flashcards
Which of the following is a machine independent programming entity?
-Object code
-Bytecode
-Binary code
-None of the above
-Bytecode
In the following Java statement, in is
Scanner sc = new Scanner(System.in);
-It’s a Scanner type object
-an InputStream type public static field in System class.s
-a method in System class
-a System type object
-an InputStream type public static field in System class.s
Which statement is most accurate:
public class Test{
public static void main(String[] args){
double radius;
final double PI=3.15169;
double area=radiusradiusPI
System.out.println(“Area is “+area);}
}
-The code will not compile because the variable radius is not initialized
-The code compiles and runs fine
-The code has no compilation error, bit it will get a runtime error because radius is not initialized
-The code has no compilation error because a constant PI is defined inside a method
-The code will not compile because the variable radius is not initialized
Which of the following modifiers can only be used, both for a local variable/reference-variable and for a field in Java?
-public
-private
-protected
-final
-static
-abstract
-final
What does the last statement in the following code segment print if the user enters the string Hello World from the keyword?
Scanner x = new Scanner(System.in);
System.out.print(“Input a string: “);
System.out.print(new String(x.nextLine());
-Hello World
-Hello
-Nothing will be printed
-Hello World
True or False: Java assigns a default value to a data field if no value is explicitly assigned to it:
-True
-False
-True
Which of the following choices is correct for the given statement:
ClassA xa = new ClassB();
-ClassA is a derived class of ClassB
-ClassB is an implemented class of an interface called ClassA
-an abstract class ClassB is a super class of ClassA
-All of the above
-None of the above
-ClassB is an implemented class of an interface called ClassA
If a class named Student has a constructor Student (String name) defined explicitly, the following constructor is implicitly provided
-public Student()
-protected Student()
-private Student()
-Student()
-None of the above is provided
-None of the above is provided
Is the following statement true or false? Multiple inheritances can be approximated by multiple interfaces
-True
Is the following statement true or false? Any data field declared in an interface is public, static, and final by default
-True
Is the following statement true or false? Interface methods are public and abstract by default
-True
Is the following statement true or false? The constructor without a parameter can only be included in an interface declaration
-False
The method____overrides the following method in a derived class.
protected double xMethod(int x){…};
-private double xMethod(int x){…}
-protected int xMethod(double x){…}
-public double xMethod(double x){…}
-public double xMethod(int x){…}
-public double xMethod(int x){…}
Can a static method access non static data of the same class?
-No
-A static method cannot access any non-static data field of the same class directly without the help of the reference variable of the same class