100% found this document useful (3 votes)
3K views

Object Oriented Programming in Java: Final Exams

The document contains a final exam for an Object Oriented Programming in Java course, with 9 multiple choice and coding questions that test concepts like data encapsulation, static vs non-static, inheritance, arrays, loops, and object instantiation. Students are instructed to label their answers and not copy from each other. The questions cover core Java topics like classes, objects, methods, variables and data types.

Uploaded by

Yas Faal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
3K views

Object Oriented Programming in Java: Final Exams

The document contains a final exam for an Object Oriented Programming in Java course, with 9 multiple choice and coding questions that test concepts like data encapsulation, static vs non-static, inheritance, arrays, loops, and object instantiation. Students are instructed to label their answers and not copy from each other. The questions cover core Java topics like classes, objects, methods, variables and data types.

Uploaded by

Yas Faal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

OBJECT ORIENTED PROGRAMMING IN JAVA

FINAL EXAMS
INSTRUCTIONS: Answer all questions and make sure you label your answers accordingly.
Copying from each other will cost you dearly. Good luck…

1. Match the correct answer to each description.


Datahiding : ………………………………….
Shared by all instances of a class: …………………………………………
Have a constant value: …………………………………………
Cannot be accessed by subclasses: ………………………………………….

2Static 3final polymorphism protect 4private interfaces 1encapsulation

2. Which of the given statements are true? (choose two)


a. Arrays are objects in java.
b. A Boolean variable of value 0 represents a false state
c. “char” variable can hold a numeric value
d. A “long” variable can hold a floating point value

3. What will be the output of the following java code?


Public class Helloworld {

Public static void main(String [] args){


int value = 7;
if(value % 3 == 2){
System.out.print(“Thumbs up! Hello world”);
}else{
System.out.print(“Thumbs down! Hello world”);
}
}
}

4. Given the following variable definition, define a getter and a setter method for it.
Private int flag = 0;

ANS: Public int get flag(){


Return flag; }
Public void set flag(int flag) {
This.flag=flag;}
5. The method definition below should return the greater of two numbers. Implement the
method.
Public double greatest (double first, double second){
}
ANS: If(first > second){
return first;
{else{ return second}

6. Use any loop to print the first 100 numbers.


ANS: For(int x = 1; x<=100; x++){ system.out.println(x + “ ”); }

7. Consider the code below and identify the errors in it. Clearly explain correctly what the
error is in each case.

public class Errors { capital and small error

static final int MIN;


public errors(){

Private int defineMin(double MIN){


MIN = MIN, ends with a comma
}

8. Assume that we defined a class called Generator. How do we create an object of this
class. ANS: Generator G = new Generator();
9. Define an integer array of size 10 and filled is with initial values.
ANS: Int my Array[] = new int [10 ];
My Array [0] = 1;
My Array[1] = 4;
My Array[2] = 5;
My Array [3] = 6;
My Array[4] = 7;
My Array[5] = 3;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy