Java Programming MCQ Part 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

20. What is the extension of compiled java classes? a) .txt b) .js c) .class d) .java

c) .class

28. What will be the output of the following Java code? class Output { public static void main(String args[]) { Integer i = new Integer(257); byte x = i.byteValue(); System.out.print(x); } } a) 257 b) 256 c) 1 d) 0

c) 1

22. What will be the output of the following Java code? class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); System.out.println(s); } } a) abc b) a c) b d) c

a) abc

16. What will be the output of the following Java code? class box { int width; int height; int length; } class main { public static void main(String args[]) { box obj = new box(); obj.width = 10; obj.height = 2; obj.length = 10; int y = obj.width * obj.height * obj.length; System.out.print(y); } } a) 100 b) 400 c) 200 d) 12

c) 200

10. Which of the following is not an OOPS concept in Java? a) Polymorphism b) Inheritance c) Compilation d) Encapsulation

c) Compilation

1. Who invented Java Programming? a) Guido van Rossum b) James Gosling c) Dennis Ritchie d) Bjarne Stroustrup

b) James Gosling

6. What is the extension of java code files? a) .js b) .txt c) .class d) .java

d) .java

4. Which one of the following is not a Java feature? a) Object-oriented b) Use of pointers c) Portable d) Dynamic and Extensible

b) Use of pointers

15. What will be the output of the following Java program? class leftshift_operator { public static void main(String args[]) { byte x = 64; int i; byte y; i = x << 2; y = (byte) (x << 2); System.out.print(i + " " + y); } } a) 0 256 b) 0 64 c) 256 0 d) 64 0

c) 256 0

3. Which component is used to compile, debug and execute the java programs? a) JRE b) JIT c) JDK d) JVM

c) JDK

30. Which of the following is a superclass of every class in Java? a) ArrayList b) Abstract class c) Object class d) String

c) Object class

26. Which of these keywords is used to define interfaces in Java? a) intf b) Intf c) interface d) Interface

c) interface

5. Which of these cannot be used for a variable name in Java? a) identifier & keyword b) identifier c) keyword d) none of the mentioned

c) keyword

13. What will be the error in the following Java code? byte b = 50; b = b * 50; a) b cannot contain value 50 b) b cannot contain value 100, limited by its range c) No error in this code d) * operator has converted b * 50 into int, which can not be converted to byte without casting

d) * operator has converted b * 50 into int, which can not be converted to byte without casting

18. What will be the output of the following Java program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } } a) 1 2 3 4 5 b) 1 2 3 4 c) 1 2 d) 1 2 3

d) 1 2 3

8. Which environment variable is used to set the java path? a) MAVEN_Path b) JavaPATH c) JAVA d) JAVA_HOME

d) JAVA_HOME

25. What will be the output of the following Java code? class output { public static void main(String args[]) { String c = "Hello i love java"; boolean var; var = c.startsWith("hello"); System.out.println(var); } } a) 0 b) true c) 1 d) false

d) false

19. What will be the output of the following Java code snippet? class abc { public static void main(String args[]) { if(args.length>0) System.out.println(args.length); } } a) The snippet compiles and runs but does not print anything b) The snippet compiles, runs and prints 0 c) The snippet compiles, runs and prints 1 d) The snippet does not compile

a) The snippet compiles and runs but does not print anything

29. What will be the output of the following Java program? class Output { public static void main(String args[]) { double x = 2.0; double y = 3.0; double z = Math.pow( x, y ); System.out.print(z); } } a) 9.0 b) 8.0 c) 4.0 d) 2.0

b) 8.0

14. Which of the following is a type of polymorphism in Java Programming? a) Multiple polymorphism b) Compile time polymorphism c) Multilevel polymorphism d) Execution time polymorphism

b) Compile time polymorphism

17. What is Truncation in Java? a) Floating-point value assigned to a Floating type b) Floating-point value assigned to an integer type c) Integer value assigned to floating type d) Integer value assigned to floating type

b) Floating-point value assigned to an integer type

21. Which exception is thrown when java is out of memory? a) MemoryError b) OutOfMemoryError c) MemoryOutOfBoundsException d) MemoryFullException

b) OutOfMemoryError

11. What is not the use of "this" keyword in Java? a) Referring to the instance variable when a local variable has the same name b) Passing itself to the method of the same class c) Passing itself to another method d) Calling another constructor in constructor chaining

b) Passing itself to the method of the same class

2. Which statement is true about Java? a) Java is a sequence-dependent programming language b) Java is a code dependent programming language c) Java is a platform-dependent programming language d) Java is a platform-independent programming language

d) Java is a platform-independent programming language

9. What will be the output of the following Java program? class output { public static void main(String args[]) { double a, b,c; a = 3.0/0; b = 0/4.0; c=0/0.0; System.out.println(a); System.out.println(b); System.out.println(c); } } a) NaN b) Infinity c) 0.0 d) all of the mentioned

d) all of the mentioned

23. Which of these are selection statements in Java? a) break b) continue c) for() d) if()

d) if()

27. What will be the output of the following Java program? class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Quiz"); StringBuffer s2 = s1.reverse(); System.out.println(s2); } } a) QuizziuQ b) ziuQQuiz c) Quiz d) ziuQ

d) ziuQ

7. What will be the output of the following Java code? class increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } a) 32 b) 33 c) 24 d) 25

a) 32

24. What will be the output of the following Java program? class recursion { int func (int n) { int result; if (n == 1) return 1; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(5)); } } a) 1 b) 120 c) 0 d) None of the mentioned

a) 1

12. What will be the output of the following Java program? class variable_scope { public static void main(String args[]) { int x; x = 5; { int y = 6; System.out.print(x + " " + y); } System.out.println(x + " " + y); } } a) Compilation error b) Runtime error c) 5 6 5 6 d) 5 6 5

a) Compilation error


Set pelajaran terkait

Health Assessment Exam 3 Practice Questions

View Set

Introduction to Java Programming: Ch. 4 quiz

View Set

CHAPTER 7: Credit cards and consumer loans

View Set

1-Network Fundamentals - Basic Question_14548700_2023_01_05_20_23

View Set

PassPoint - Mood, Adjustment, and Dementia Disorders

View Set

NCLEX Questions for Nursing 102 Exam #2

View Set

Math SAT Level I - Chapter 4 Ratios and Proportions

View Set

E-business Management- Ch.10 Online Content and Media

View Set

Unit 17 - Alternative Investments and Other Assets

View Set

Weeks 2-6 Concepts: Poli Sci 1155 - class notes

View Set