0% found this document useful (0 votes)
5 views8 pages

A. Accessor and Mutator Methods

The document contains a series of multiple-choice questions related to Java programming concepts, including access modifiers, object-oriented programming principles, and constructors. It also includes code snippets and asks for expected outputs based on Java syntax and logic. The questions cover topics such as encapsulation, inheritance, polymorphism, and interfaces.

Uploaded by

kramyaj031704
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)
5 views8 pages

A. Accessor and Mutator Methods

The document contains a series of multiple-choice questions related to Java programming concepts, including access modifiers, object-oriented programming principles, and constructors. It also includes code snippets and asks for expected outputs based on Java syntax and logic. The questions cover topics such as encapsulation, inheritance, polymorphism, and interfaces.

Uploaded by

kramyaj031704
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
You are on page 1/ 8

1.

In order for as to encapsulate and to restrict access directly to an instance variable, we use
__________ and ___________ to access, change or assign value of instance variable.

A. Accessor and Mutator methods

B. Accessor and Constructor methods

C. Mutator and Modifier

D. Constructor and Modifier

2. If you want your class, methods or fields accessible everywhere, you need to define what type of
access modifier?

A. Default

B. Protected

C. Public

D. Private

3. Which of the following is true about subclass?

A. Subclass is abstract class

B. Subclass can be inherited from another class

C. Subclass cannot access the private fields of the parent class

D. Subclass can be inherited from another subclass

4. In java we cannot create instance of this reference type. This applies to?

A. Inheritance

B. Polymorphism

C. Encapsulation

D. Abstraction

E. Interface

5. It is a reference type of Java that do not have a constructor.

A. Inheritance

B. Polymorphism

C. Encapsulation

D. Abstraction

E. Interface
6. This access modifier can only be used to a methods or fields and can only be used either on the same
package or in sub-classes?

A. Default

B. Protected

C. Public

D. Private

7. Which of the following describes the constructor?

A. It is a method

B. It is a field

C. It is an object

D. It is a property

8-11. Enumerate the 4 types of Access Modifiers in Java.

1. Private

2. Default

3. Protected

4. Public

12. In java we can define 2 or more constructors as long as they have different number and type of
parameters. This approach is what we called?

A. Method overriding

B. Method overloading

C. Method access control

D. Inheritance

13. When using this modifier to a class, methods or fields this means that it can only be accessed with in
the class itself?

A. Default

B. Protected

C. Public

D. Private
14. What would be the result of the following code?

package StringMethods;

public class Text extends MotherClass, FatherClass{

A. Properties of MotherClass and ParentClass will be inherited by the Test Class

B. Compile error

C. Runtime Error

D. Test class can be inherited from another class

15. If the constructor is private this resulted to?

A. We cannot create an instance of the class outside it class

B. We cannot create an instance of the class from its subclass

C. We cannot create an instance of the class within its class

D. We cannot create an instance of the class anywhere in our program

16. What would be the result of the following program, when you assign an integer 5 using the console?

import java util Scanner;

public class Test {

Scanner scan = null;

public Test() {

int x = scan.nextInt();

A. x = 5

B. Compile error

C. Runtime Error

D. x = null

17. This concepts in Object Oriented Programming that allows an object to be created differently from
the same class.

A. Inheritance

B. Polymorphism

C. Encapsulation

D. Abstraction
18. This type of methods that do not have the body on it’s class.

A. static

B. private

C. protected

D. abstract

19. A method can return literals and object.

A. True

B. False

C. Only literals

D. Only object

20. In java, when you want to define the methods that is repeating and do same action to several
classes, it is suggested to use the ___________.

A. Inheritance

B. Polymorphism

C. Method overloading and Method overloading

D. Interface

21. This concepts in Object Oriented Programming that you can acquire the methods and fields of a
class.

A. Inheritance

B. Polymorphism

C. Encapsulation

D. Abstraction

22-23. Enumerate the 2 types of Polymorphism.

1. Compile-time Polymorphism (static polymorphism)

2. Run-time Polymorphism (dynamic polymorphism)

24. This type of class which exist only for the purpose of Polymorphism and Inheritance.

A. static

B. private

C. protected

D. abstract
25. This is the OOP concept hides the implementation details from a user and highlighting only the
important part?

A. Inheritance

B. Polymorphism

C. Encapsulation

D. Abstraction

26. What type of access modifier when you supply no modifier at all to a class, methods or fields?

A. Default

B. Protected

C. Public

D. Private

27. Which of the following is true about subclass?

A. Subclass is abstract class

B. Subclass can be inherited from another class

C. Subclass cannot access the private fields of the parent class

D. Subclass can be inherited from another subclass

28. In order for us to get value from a methods, we will use the keyword _______?

A. public

B. static

C. return

D. get

29. In java, when we a derived class has a definition for one of the member of the base class is what we
called?

A. Method overriding

B. Method overloading

C. Method access control

D. Inheritance

30. A constructor have a return value.

A. True

B. False
31. Which of the following is not true about Interface?

A. An interface can contain any number of methods.

B. An interface is written in a file with a .java extension, with the name of the interface matching the
name of the file

C. The byte code of an interface appears in a .class file

D. Interfaces appear in packages, and their corresponding bytecode file must be in a directory structure
that matches the package name.

E. None of the above

32. If you want to implements the Interface from a class, you need to supply what java keyword to a
class definition?

A. extends

B. implements

C. acquire

D. override

33. This is the OOP concept that variables of a class will be hidden from other classes, and can be
accessed only through the methods of their current class.

A. Inheritance

B. Polymorphism

C. Encapsulation

D. Abstraction

34. The interface and Interface methods are explicitly abstract.

A. true

B. False

C. Maybe

35 – 36.

Aw Aw

37 – 40 . Write the output of the following program


1000
1001
1002
1003
1004
1005
41- 50:

41. Hero

42. Player

43. package com.buksu.it.game;


44. Items

45. extends

46. FireArms

47. Pistol

48. FireArms

49. class

50. Player

51- 108
package com.buksu.it.game;

public class Main {


public static void main(String[] args) {
Team delta = new Team("Delta Team");
new Team("Omega Team");

Player delta_one = new Hero("Mark");


Player delta_two = new Hero("Jason");
Player delta_three = new Hero("David");
Player delta_four = new Hero("Leo");
Player delta_five = new Hero("Kevin");

delta.addPlayerToSquad(delta_one);
delta.addPlayerToSquad(delta_two);
delta.addPlayerToSquad(delta_three);
delta.addPlayerToSquad(delta_four);
delta.addPlayerToSquad(delta_five);
}
}
51 – 108:
package com.buksu.it.game;
public class Main {
public static void main(String[] args) {
Team delta = new Team("Delta Team");
Team omega = new Team("Omega Team");

Player delta_one = new Hero("Mark");


Player delta_two = new Hero("Jason");
Player delta_three = new Hero("David");
Player delta_four = new Hero("Leo");
Player delta_five = new Hero("Kevin");

delta.addPlayerToSquad(delta_one);
delta.addPlayerToSquad(delta_two);
delta.addPlayerToSquad(delta_three);
delta.addPlayerToSquad(delta_four);
delta.addPlayerToSquad(delta_five);

Player omega_one = new Enemy("Angel");


Player omega_two = new Enemy("Mae");
Player omega_three = new Enemy("Ann");
Player omega_four = new Enemy("Kristine");
Player omega_five = new Enemy("Gwen");

omega.addPlayerToSquad(omega_one);
omega.addPlayerToSquad(omega_two);
omega.addPlayerToSquad(omega_three);
omega.addPlayerToSquad(omega_four);
omega.addPlayerToSquad(omega_five);

Items pistol = new Pistol();


Items shotgun = new Shutgun();
Items bag = new Bag();

delta_one.addItems(pistol);
delta_one.addItems(bag);

omega_one.addItems(shotgun);
omega_one.addItems(bag);

}
}

You might also like