Choose the correct statementpublic class Circle{ private double radius; public Circle(double radius){ radius = radius; }} The program has a compilation error because we cannot assign radius to radius. The program has a compilation error because it does not have a main method. The program will compile, but we cannot create an object of Circle with a specified radius. The object will always have radius 0. The program does not compile because Circle does not have a default constructor. TRUE ANSWER : ? YOUR ANSWER : ?
A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction? Declare the method with the keyword public. Declare the method with the keyword protected. Do not declare the method with any accessibility modifiers. Declare the method with the keyword public and private. Declare the method with the keyword private. TRUE ANSWER : ? YOUR ANSWER : ?
A package is a collection of Interfaces Editing tools Classes Editing tools and Interfaces Classes and Interfaces TRUE ANSWER : ? YOUR ANSWER : ?
Choose the correct statement. Restriction on static methods are: I. They can only call other static methods.II. They must only access static data.III. They cannot refer this or super in any way. Only (III) Only (I) (II) and (III) (I), (II) and (III) (I) and (II) TRUE ANSWER : ? YOUR ANSWER : ?
What will be the output after the following program is compiled and executed?public class Test{ public static void main(String args[]){ int x = 10; x = myMethod(x--); System.out.print(x); } static int myMethod(final int x){ return x--; }} None of these The program will lead to compilation error. The program will lead to runtime error. The will compile successfully and display 9 as output. The program will compile successfully and display 10 as output. TRUE ANSWER : ? YOUR ANSWER : ?
You have the following code in a file called Test.javaclass Base{ public static void main(String[] args){ System.out.println("Hello"); }}public class Test extends Base{}What will happen if you try to compile and run this? Runtime error Compiles and runs with no output. It will fail to compile. Compiles and runs printing TRUE ANSWER : ? YOUR ANSWER : ?
What is the result of compiling and running the following code?public class Tester{static int x = 4;int y = 9; public Tester(){System.out.print(this.x); // line 1printVariables();}public static void printVariables(){System.out.print(x); // line 2System.out.print(y); // line 3}public static void main(String... args) { // line 4new Tester();}} Compile error at line 2 (must access x by writing Tester.x) Compile error at line 1 (static x must be only accessed inside static methods) Compile error at line 4 (invalid argument type for method main) Compile error at line 3 (static methods can't make reference to non-static variables) 49 TRUE ANSWER : ? YOUR ANSWER : ?
Determine output:class A{{System.out.print("b1 ");}public A(){System.out.print("b2 ");}}class B extends A{static{System.out.print("r1 ");}public B(){System.out.print("r2 ");}{System.out.print("r3 ");}static{System.out.print("r4 ");}}public class Test extends B{public static void main(String[] args){System.out.print("pre ");new Test();System.out.println("post ");}} r1 r4 pre b1 b2 r3 r2 post pre r1 r4 b1 b2 r2 r3 post r1 r4 pre b1 b2 post r1 r4 pre b1 b2 post r3 r2 Compilation fail TRUE ANSWER : ? YOUR ANSWER : ?
The object is created with new keyword At Compile-time At run-time None of these Depends on the code TRUE ANSWER : ? YOUR ANSWER : ?
Choose all the lines which if inserted independently instead of "//insert code here" will allow the following code to compile:public class Test{ public static void main(String args[]){ add(); add(1);add(1, 2); }// insert code here} static void add(int args...){} void add(Integer... args){} static void add(int...args){} static void add(int... args, int y){} static void add(int[]... args){} TRUE ANSWER : ? YOUR ANSWER : ?