What will happen when you attempt to compile and run the following code
public class Hope{ public static void main(String argv[]){ Hope h = new Hope(); } protected Hope(){ for(int i =0; i <10; i ++){ System.out.println(i); } } }
Compilation and running with output 0 to 9
Run time error: Constructors cannot be declared protected
Compilation error: Constructors cannot be declared protected
Compilation and running with output 0 to 10
None of the above
What is output of the above program?
Class conditional { public static void main(String args[]) { int i = 20; int j = 55; int z = 0; z = i < j ? i : j; // ternary operator System.out.println("The value assigned is " + z); } }
20
55
Which of the following statements are true?
Strings are a primitive type in Java and the StringBuffer is used as the matching wrapper type
The size of a string can be retrieved using the length property.
Strings are a primitive type in Java that overloads the + operator for concatenation
The String class is implemented as a char array, elements are addressed using the stringname[] convention
A class cannot be declared:
Static
Private
Default
Following code will result in:
int a1 = 5; double a2 = (float)a1;
Compilation error
Runtime error
No errors
Execptions
class A { int b = 1; public static void main(String [] args) { System.out.println("b is " + b); } }
Runtime Error
Runtime Exception
Output of b is 1
class A { public static void main(String [] args) { B b = new A(); } } class B extends A {}
Other Execptions
What is an instance of
A methods in object
An operator and keyword
Both
None
What happens when you do if (a==b)?
Integer a = new Integer(2); Integer b = new Integer(2);
Compiler error
FALSE
What is the size of a Char?
4 bits
7 bits
8 bits
16 bits