public class Program
{
private int num; private Program(){ System.out.print("Constructor"); num=5; } public static void main(String[] args) { Program p=new Program(); System.out.println(p.num); } }
{
private int num; private Program(){ System.out.print("Constructor"); num=5; } public static void main(String[] args) { Program p=new Program(); System.out.println(p.num); } }
Anonymous Quiz
32%
Compile Time Error
14%
0
55%
Constructor 5
0%
No Output
public class Program
{
public static void main(String[] args) { int t; System.out.println(t); } }
{
public static void main(String[] args) { int t; System.out.println(t); } }
Anonymous Quiz
39%
0
35%
Compile Time Error
17%
Runtime Error
9%
None Of the Above
JAVA Cheat Sheet. A cheat-sheet for reading right before… | by Anjali Viramgama | Nov, 2020 | Medium
https://medium.com/@anjaliviramgama/java-cheat-sheet-4b1ce58967e9
https://medium.com/@anjaliviramgama/java-cheat-sheet-4b1ce58967e9
Medium
JAVA Cheat Sheet
A cheat-sheet for reading right before an interview, or while solving programming questions in JAVA.
Functionality of multiple inheritance can be implemented in java by
A) Extending one class and implementing multiple Interfaces
B)Implementing multiple Interfaces C)Extending multiple classes and interfaces D)Extending multiple classes and one Interface
A) Extending one class and implementing multiple Interfaces
B)Implementing multiple Interfaces C)Extending multiple classes and interfaces D)Extending multiple classes and one Interface
Anonymous Quiz
37%
Only A
11%
Only B
26%
A & B
26%
B & C
Which of the following variable declaration would NOT compile in a java program?
Anonymous Quiz
0%
int var;
4%
int VAR;
8%
int var1;
4%
int var_1;
85%
int 1_var;
Consider the following class definition:
public class MyClass
{
private int value;
public void setValue(int i){ /* code */ }
// Other methods...
}
The method setValue assigns the value of i to the instance field value. What could you write for the
implementation of setValue?
(a) value = i;
(b) this.value = i;
(c) value == i;
(d) Both (A) and (B) and above
(e) (A), (B) and (C) above.
public class MyClass
{
private int value;
public void setValue(int i){ /* code */ }
// Other methods...
}
The method setValue assigns the value of i to the instance field value. What could you write for the
implementation of setValue?
(a) value = i;
(b) this.value = i;
(c) value == i;
(d) Both (A) and (B) and above
(e) (A), (B) and (C) above.
Which of the following is TRUE?
Anonymous Quiz
0%
In java, an instance field declared public generates a compilation error.
6%
int is the name of a class available in the package java.lang
24%
Instance variable names may only contain letters and digits.
65%
A class has always a constructor (possibly automatically supplied by the java compiler).
6%
The more comments in a program, the faster the program runs.
Consider,
public class MyClass
{ public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write?
public class MyClass
{ public MyClass(){/*code*/} // more code... } To instantiate MyClass, you would write?
Anonymous Quiz
65%
(a) MyClass mc = new MyClass();
6%
(b) MyClass mc = MyClass();
6%
(c) MyClass mc = MyClass;
12%
(d) MyClass mc = new MyClass;
12%
(e) The constructor of MyClass should be defined as, public void MyClass(){/*code*/}.
7 Hacks to become a better Java problem-solver | TechGig
https://content.techgig.com/7-hacks-to-become-a-better-java-problem-solver/articleshow/79468180.cms
https://content.techgig.com/7-hacks-to-become-a-better-java-problem-solver/articleshow/79468180.cms
TechGig
7 Hacks to become a better Java problem-solver
By Kajal Garg For a Java developer, transforming into a professional programmer is not that tricky and the most expected quality to become one is to detect
What is byte code in the context of Java?
Anonymous Quiz
43%
The type of code generated by a Java compiler.
40%
The type of code generated by a Java Virtual Machine.
10%
It is another name for a Java source file.
7%
It is the code written within the instance methods of a class.
0%
It is another name for comments written within a program.
What is garbage collection in the context of Java?
Anonymous Quiz
7%
The operating system periodically deletes all the java files available on the system.
23%
Any package imported in a program and not used is automatically deleted.
60%
When all references to an object are gone the memory used by the object is automatically reclaimed
10%
The JVM checks the output of any Java program and deletes anything that doesn't make sense.
You read the following statement in a Java program that compiles and executes.
submarine.dive(depth);
What can you say for sure?
submarine.dive(depth);
What can you say for sure?
Anonymous Quiz
0%
depth must be an int
23%
dive must be a method.
32%
dive must be the name of an instance field.
36%
submarine must be the name of a class
9%
submarine must be a method.
The java run time system automatically calls this method while garbage collection.
Anonymous Quiz
9%
finalizer()
55%
finalize()
24%
finally()
12%
finalized()
The correct order of the declarations in a Java program is,
Anonymous Quiz
59%
Package declaration, import statement, class declaration
19%
Import statement, package declaration, class declaration
15%
Import statement, class declaration, package declaration
7%
Class declaration, import statement, package declaration
0%
Class declaration, package declaration, import statement
An overloaded method consists of,
Anonymous Quiz
19%
(a) The same method name with different types of parameters
19%
(b) The same method name with different number of parameters
16%
(c) The same method name and same number and type of parameters with different return type
39%
(d) Both (a) and (b) above
6%
(e) (a), (b) and (c) above.
A protected member can be accessed in,
Anonymous Quiz
23%
a subclass of the same package
13%
a non-subclass of the same package
16%
a non-subclass of different package
23%
a subclass of different package
26%
the same class.
What is the output of the following code:
class eq
{ public static void main(String args[]) { String s1 = “Hello”; String s2 = new String(s1); System.out.println(s1==s2); } }
class eq
{ public static void main(String args[]) { String s1 = “Hello”; String s2 = new String(s1); System.out.println(s1==s2); } }
Anonymous Quiz
35%
true
53%
false
12%
0
0%
1