Q1. What is the output of this code?
class Main { public static void main (String[] args) { String message = “Hello world!”; String newMessage = message.substring(6, 12) + message.substring(12, 6); System.out.println(newMessage); }}
Q2. How do you write a foreach loop that will iterate over ArrayList<Pencil>pencilCase?
Q3. Fill in the blanks?
Object-oriented programming (OOP) is a programming language model that organizes software design around (objects), rather than (actions).
Q4. What code would you use to tell if “schwifty” is of type String?
Q5. Correct output of “apple”.compareTo(“banana”)
Q6. You have an ArrayList of names that you want to sort alphabetically. Which approach would NOT work?
Q7. By implementing encapsulation, you cannot directly access the class’s _____ properties unless you are writing code inside the class itself.
Q8. Which is the most up-to-date way to instantiate the current date?
Q9. Fill in the blank to create a piece of code that will tell wether int0 is divisible by 5:
Q10. How many time will this code print “Hello World!”?
Class Main {
public static void main(String[] args){
for (int i=0; i<10; i=i++){
i+=1;
System.out.println(“Hello World!”);
}
}
}
Q11. The runtime system starts your program by calling which function first?
Q12. What is the result of this code?
try{
System.out.print(“Hello World”);
}catch(Exception e){
System.out.println(“e”);
}catch(ArithmeticException e){
System.out.println(“e”);
}finally{
System.out.println(“!”);
}
Q13. Which statement is NOT true?
Q14. What will this program print out to the console when executed?
public class Main {
public static void main(String[] args){
LinkedList<Integer> list = new LinkedList<>();
list.add(5);
list.add(1);
list.add(10);
System.out.println(list);
}
}
Q15. What is the output of this code?
class Main {
public static void main(String[] args){
String message = “Hello”;
for (int i = 0; i<message.length(); i++){
System.out.print(message.charAt(i+1));
}
}
}
Q16. Object-oriented programming is a style of programming where you organize your program around ____ rather than ____ and data rather than logic.
Q17. Given the string “strawberries” saved in a variable called fruit, what would “fruit.substring(2, 5)” return?
Q18. How can you achieve runtime polymorphism in Java?
Q19. Given the following definitions, which of these expressions will NOT evaluate to true?
boolean b1 = true, b2 = false;
int i1 = 1, i2 = 2;
Q20. What can you use to create new instances in Java?
Q21. What is the output of this code?
class Main {
public static void main (String[] args) {
int array[] = {1, 2, 3, 4};
for (int i = 0; i < array.size(); i++) {
System.out.print(array[i]);
}
}
}
Q22. Which of the following can replace the CODE SNIPPET to make the code below print “Hello World”?
interface Interface2 {
static void print() {
System.out.print(“World!”);
}
}
Q23. What does the following code print?String str = “”abcde””;str.trim();str.toUpperCase();str.substring(3, 4);System.out.println(str);
Q24. What is the result of this code?
class Main {
public static void main (String[] args){
System.out.println(print(1));
}
static Exception print(int i){
if (i>0) {
return new Exception();
}
else {
throw new RuntimeException();
}
}
}
Q25. Which class can compile given these declarations?
interface One {
default void method() {
System.out.println(“”One””);
} }
interface Two {
default void method () {
System.out.println(“”One””);
}
}
publc void method() { super.One.method(); } }
publc void method() { One.method(); } }
}
publc void method() { One.super.method(); } }
Q26. What is the output of this code?
class Main {
public static void main (String[] args) {
List list = new ArrayList();
list.add(“hello”);
list.add(2);
System.out.print(list.get(0) instanceof Object);
System.out.print(list.get(1) instanceof Integer);
}
}
Q27. Given the following two classes, what will be the output of the Main class?
package mypackage;
public class Math {
public static int abs(int num){
return num<0?-num:num;
}
}
package mypackage.elementary;
public class Math {
public static int abs (int num) {
return -num;
}
}
import mypackage.Math;
import mypackage.elementary.*;
class Main {
public static void main (String args[]){
System.out.println(Math.abs(123));
}
}
Q28. What is the result of this code?
class MainClass {
final String message(){
return “Hello!”;
}
}
class Main extends MainClass {
public static void main(String[] args) {
System.out.println(message());
}
String message(){
return “World!”;
}
}
Q29. Given this code, which command will output “2”?
class Main {
public static void main(String[] args) {
System.out.println(args[2]);
}
}
Q30. What is the output of this code?
class Main { public static void main(String[] args){ int a = 123451234512345; System.out.println(a); }}
Q31. What is displayed when this code is compiled and executed?
Public class main {
public static void main(string[] args) {
int x= 5;x = 10;System.out.println(x);
}
}
Q32. What statement returns true if “nifty” is of type String?
Q33. Given the string “strawberries” saved in a variable called fruit, what would fruit .substring(2, 5) return?
Q34. What is the result of this code?
try{ System.out.print(“Hello World”);}catch(Exception e) { System.out.println(“e”);}catch(ArithmeticException e) { System.out.println(“e”);}finalyy{ System.out.println(“!”);}
Q35. How many times will this code print “Hello World”?
class Main{ public static void main(String[] args) {
for (int i=0; i<10; i=i++){ i+=1; System.out.println(“Hello World!”); } }}
Q36. What is the result of this code?
class Main { Object message(){ return “Hello!”;
} public static void main(String[] args) { System.out.print(new main().MESSAGE()); System.out.print(new Main2().message()); }}class Main2 extends Main { String message(){ return “World!”; }}
Q37. You have an ArrayList of names that you want to sort alphabetically. Which approach would not work?
s1.compareTo(s2)).collect(Collectors.toList())
Q38. What is the output of this code?
import java.util.*;class Main { public static void main(String[] args) { List<Boolean> list = new ArrayList<>(); list.add(true); list.add(Boolean.parseBoolean(“False”)); list.add(Boolean.TRUE); System.out.print(list.size()); System.out.print(list.get(1) instanceof Boolean); }}
Q39. What method can be used to create a new instance of an object?
Q40. How can you achieve runtime polymorphism in Java?
Q41. What is the output of this code?
class Main { public static void main(String[] args) { String message = “Hello wold!”; String newMessage = message.substring(6, 12) + message.substring(12, 6); System.out.println(newMessage); }}
Q42. Which is the most reliable expression for testing whether the values of two string variables are the same?
Q43. What is the output of this code?
class Main {
static int cound = 0;
public static void main(String[] args) {
if(cound <3)
{count++;main(null);}
else{ return;
} System.out.println(“Hello World”);
}
}
Q44. What is the output of this code?
class main {
public static void main(String[] args) {
List list = new ArrayList(); list.add(“hello”);
list.add(2);
System.out.print(list.get(0) instanceof Object); System.out.print(list.get(1) instanceof Integer);
}
}
Q45. By implementing encapsulation, you cannot directly access the class’s_____properties unless you are writing code inside the class itself.
Java is an object-oriented programming language with a high level of abstraction and as few implementation dependencies as possible. It is a general-purpose programming language that allows application developers to write once and run anywhere (WORA), which means that compiled Java code can operate on any platform that supports Java without the need to recompile. Java applications are usually compiled to bytecode, which may execute on any Java virtual machine (JVM), regardless of the computer architecture.
Have you ever had a dream about an abacus? In a dream, seeing an abacus…
Have you ever had a dream about abalone? It denotes a period of change in…
Have you ever had a dream about being abandoned? It's time to let go of…
Did you have any dreams about giving advice? They have to do with action plans…
Have you ever had a dream involving an avalanche? In your dream, an avalanche represents…
Have you ever fantasised about acrobats or about becoming one? It indicates that you need…