0% found this document useful (0 votes)
28 views14 pages

Practice Test-1

The document consists of a series of multiple-choice questions related to Object-Oriented Programming (OOP) concepts in Java, covering topics such as inheritance, encapsulation, polymorphism, and exception handling. Each question presents four options, with only one correct answer for each. The questions assess knowledge of Java syntax, OOP principles, and common methods associated with strings and exceptions.

Uploaded by

deeptasermaraj06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views14 pages

Practice Test-1

The document consists of a series of multiple-choice questions related to Object-Oriented Programming (OOP) concepts in Java, covering topics such as inheritance, encapsulation, polymorphism, and exception handling. Each question presents four options, with only one correct answer for each. The questions assess knowledge of Java syntax, OOP principles, and common methods associated with strings and exceptions.

Uploaded by

deeptasermaraj06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. Which of the following is not a principle of OOP?

A. Inheritance

B. Encapsulation

C. Compilation

D. Polymorphism

2. Which concept allows the same method name to behave differently based on context?

A. Inheritance

B. Polymorphism

C. Abstraction

D. Encapsulation

3. OOP improves code by making it more...

A. Static

B. Structured

C. Modular and reusable

D. Compiled

4. What keyword is used to create an object in Java?

A. make

B. build

C. new

D. create

5. Which of the following correctly creates an object of class `Person`?

A. Person p = new Person();

B. p = new Person();

C. Person = new p();

D. new Person p();

6. Which access modifier allows visibility within the same package only?

A. private

B. public

C. protected

D. default

Page 1
7. Inheritance supports which of the following features?

A. Code redundancy

B. Code reuse

C. Code hiding

D. None of the above

8. Which keyword is used for inheritance in Java?

A. inherits

B. this

C. extends

D. super

9. If class B extends class A, which of the following is true?

A. A is a subclass of B

B. B is a subclass of A

C. A and B are unrelated

D. Compilation error

10. Polymorphism is implemented using...

A. Overloading

B. Overriding

C. Both

D. None

11. Which of the following is not a type of polymorphism in Java?

A. Compile-time

B. Runtime

C. Static

D. Dynamic binding

12. Method overloading is an example of...

A. Runtime polymorphism

B. Compile-time polymorphism

C. Dynamic method dispatch

D. Data abstraction

Page 2
13. Which keyword is used to achieve abstraction in Java?

A. final

B. static

C. abstract

D. interface

14. Which is true about encapsulation?

A. Data and methods are separated

B. Data is hidden using private access

C. No relation to classes

D. It cannot be overridden

15. How can you access private members of a class?

A. Directly

B. With super

C. Using public getters/setters

D. Using this

16. Which class is immutable in Java?

A. StringBuilder

B. StringBuffer

C. String

D. CharArray

17. Which method returns the length of a string?

A. size()

B. getLength()

C. length()

D. count()

18. What will 'abc'.concat('def') return?

A. abcdef

B. abc def

C. defabc

D. Error

Page 3
19. Which method converts a string to uppercase?

A. toUpper()

B. upper()

C. toUpperCase()

D. makeUpper()

20. Which method checks if two strings are equal ignoring case?

A. isEqual()

B. equalsIgnoreCase()

C. match()

D. compare()

21. Which method replaces characters in a string?

A. substitute()

B. replace()

C. change()

D. edit()

22. Which block must always be followed after a try block?

A. catch

B. finally

C. catch or finally

D. throw

23. Which keyword is used to manually throw an exception?

A. throw

B. throws

C. final

D. error

24. Which keyword is used to declare that a method might throw an exception?

A. throw

B. finally

C. throws

D. exception

Page 4
25. Which exception is unchecked in Java?

A. IOException

B. SQLException

C. NullPointerException

D. FileNotFoundException

26. What will be the output?

class Test {

int x = 10;

public static void main(String[] args) {

Test t = new Test();

[Link](t.x);

A. Option 1

B. Option 2

C. Option 3

D. Option 4

27. Which line will cause an error?

class Demo {

private int x = 100;

public class Main {

public static void main(String[] args) {

Demo d = new Demo();

[Link](d.x);

A. Option 1

Page 5
B. Option 2

C. Option 3

D. Option 4

28. Which constructor is called?

class Animal {

Animal() {

[Link]("Animal");

Animal(String name) {

[Link]("Name: " + name);

public static void main(String[] args) {

new Animal();

A. Option 1

B. Option 2

C. Option 3

D. Option 4

29. What's the output?

class Student {

String name = "Alex";

void display() {

[Link](name);

public static void main(String[] args) {

Student s = new Student();

Page 6
[Link]();

A. Option 1

B. Option 2

C. Option 3

D. Option 4

30. What will this print?

class Parent {

void show() {

[Link]("Parent");

class Child extends Parent {

void display() {

show();

public static void main(String[] args) {

Child c = new Child();

[Link]();

A. Option 1

B. Option 2

C. Option 3

D. Option 4

31. Which keyword is used to call parent class constructor?

class A {

Page 7
A() {

[Link]("A");

class B extends A {

B() {

super();

[Link]("B");

A. Option 1

B. Option 2

C. Option 3

D. Option 4

32. Output?

class A {

void print() {

[Link]("A");

class B extends A {

void print() {

[Link]("B");

public class Main {

public static void main(String[] args) {

Page 8
A obj = new B();

[Link]();

A. Option 1

B. Option 2

C. Option 3

D. Option 4

33. Which concept is used here?

class Shape {

void draw() {

[Link]("Drawing Shape");

class Circle extends Shape {

void draw() {

[Link]("Drawing Circle");

A. Option 1

B. Option 2

C. Option 3

D. Option 4

34. Which line causes an error?

abstract class Animal {

abstract void sound();

class Dog extends Animal {

Page 9
void sound() {

[Link]("Bark");

public static void main(String[] args) {

Dog d = new Dog();

[Link]();

A. Option 1

B. Option 2

C. Option 3

D. Option 4

35. Why is encapsulation useful?

class Account {

private double balance;

public void deposit(double amount) {

balance += amount;

A. Option 1

B. Option 2

C. Option 3

D. Option 4

36. What will this print?

String s = "hello";

[Link](" world");

[Link](s);

A. Option 1

Page 10
B. Option 2

C. Option 3

D. Option 4

37. Which returns true?

String a = "Java";

String b = new String("Java");

[Link]([Link](b));

A. Option 1

B. Option 2

C. Option 3

D. Option 4

38. Output?

String s = " hello ";

[Link]([Link]());

A. Option 1

B. Option 2

C. Option 3

D. Option 4

39. Which method replaces text in a string?

String s = "cat";

[Link]([Link]('c', 'b'));

A. Option 1

B. Option 2

C. Option 3

D. Option 4

40. What will happen?

int x = 10 / 0;

[Link]("Hello");

A. Option 1

Page 11
B. Option 2

C. Option 3

D. Option 4

41. Which block executes no matter what?

try {

[Link](5/0);

} catch (Exception e) {

[Link]("Error");

} finally {

[Link]("Finally");

A. Option 1

B. Option 2

C. Option 3

D. Option 4

42. Which keyword is used to define exceptions that a method might throw?

public void readFile() throws IOException {

// code

A. Option 1

B. Option 2

C. Option 3

D. Option 4

43. Output?

class A {

A() {

[Link]("A");

Page 12
}

class B extends A {

B() {

[Link]("B");

class C extends B {

C() {

[Link]("C");

public static void main(String[] args) {

C obj = new C();

A. Option 1

B. Option 2

C. Option 3

D. Option 4

44. Output of this method?

public int sum(int... nums) {

int total = 0;

for (int n : nums) total += n;

return total;

[Link](sum(1,2,3));

A. Option 1

B. Option 2

C. Option 3

Page 13
D. Option 4

45. What is the output?

interface A {

void show();

class B implements A {

public void show() {

[Link]("Interface implemented");

public static void main(String[] args) {

A obj = new B();

[Link]();

A. Option 1

B. Option 2

C. Option 3

D. Option 4

Page 14

You might also like