Introduction to Object Oriented Programming Concepts

Exercise Questions

Fill in the blanks:

  1. An act of using essential features without including background details is called data abstraction.
  2. In Object Oriented Programming, the stress is given on data.
  3. Wrapping of data and functions together as a single unit is called encapsulation.
  4. An object has unique identity through which it may differ with some characteristics and behavior.
  5. The objects may communicate with each other through functions.
  6. In POP, the global data is loosely attached to the functions.
  7. The process by which a class acquires the property of another class is known as inheritance.
  8. In Object Oriented Programming, using a function for many purposes is termed as polymorphism.

State whether True or False:

  1. A process according to which a class acquires the characteristics from another class is encapsulation. (FALSE)
  2. Procedure Oriented Program stresses on data. (FALSE)
  3. C++ is also an object-oriented programming language. (TRUE)
  4. A function is a set of objects that share common state and behavior. (FALSE)
  5. Encapsulation keeps data safe from outside interference. (TRUE)

Answer the following questions

  1. What is meant by object oriented programming?
    It is a modular approach which allows the data to be applied within the given program area.
  2. What are the elements of object oriented programming?
    Objects, Classes, Data Abstraction, Inheritance, Polymorphism, Encapsulation.
  3. List the features of object oriented programming.
    This approach is useful in solving complex problems.
    OOP stresses on data.
  4. In what ways object oriented programming is different from procedure oriented programming language?
    OOP emphasizes on data whereas POP emphasizes on functions.
  5. Name any two object oriented programming principles.
    Encapsulation, Polymorphism.
  6. Name any two object oriented programming and procedure oriented programming languages.
    Java and Python are OOP languages.
    BASIC and C are POP languages.
  7. Which OOP principle implements function overloading?
    Polymorphism.
  8. Define the following terms:
    a) Encapsulation with an example.
    Wrapping up of data and functions in a class so that they can be used as a single unit is called encapsulation. For example, keeping both data and functions within a class such that only the member functions can access the data within the class.
    b) Data Abstraction with an example.
    It is the act of representing essential features without knowing the background details. For example, the private data members in a class are hidden from unintentional changes.
  9. Explain inheritance with a suitable example.
    Inheritance is an OOP principle by which a class acquires some features from another class. It helps in reusing of code. For example, an SUV is a car that inherits all the features of a general car, and also adds some unique properties and features to itself.
  10. What is meant by polymorphism? Explain with an example.
    It is the process of using a function for more than one purpose. For example, Math.abs() implements polymorphism because it works with both integers and floating-point numbers.

Exercise Questions

Write True or False:

  1. Java application is a Java program which is developed by users. (FALSE)
  2. James Gosling developed Java programming language. (TRUE)
  3. Machine codes are expressed using alphanumeric characters. (FALSE)
  4. Bytecode is the program in binary form. (TRUE)
  5. JVM is Java Visual Management. (FALSE)

Fill in the blanks:

  1. Java is a case-sensitive language.
  2. In Java, the package used to find power raised to any base is java.lang.
  3. The words which are preserved with the system are called reserved words, that cannot be used as variable names in Java programming.
  4. A single line comment is represented by the symbol // in Java programming.
  5. BlueJ is a window based platform to operate Java program.

Answer the following questions:

  1. Who developed Java? What was it initially called?
    James Gosling developed Java. Java was initially called Oak.
  2. Give a brief historical development of Java.
    Sun Microsystems initially developed this language to develop software for consumer electronics. But its platform independence feature made it popular as a general purpose programming language.
  3. Mention at least four features of Java.
    a) It is an object oriented programming language.
    b) It uses both compiler and interpreter.
    c) It is case-sensitive.
    d) It is a platform independent programming language.
  4. Define the following:
    a) A compiler: Program that converts high-level language program into low-level language program at once.
    b) An interpreter: Program that converts high-level language program into low-level language program line by line.
    c) Bytecode: Intermediate code that is generated after a Java source code is compiled. It is platform independent, and only needs JVM for execution.
  5. What is Java Virtual Machine (JVM)?
    JVM is the interpreter that is responsible for executing the bytecode. It acts as a virtual processor for Java, making it platform independent because the program directly doesn’t depend on the physical processor.
  6. Name three packages of Java class library.
    java.io, java.lang, java.util.
  7. What are Java reserved words? Name any five.
    Reserved words are the keywords that have a special meaning in a program. It cannot be used as an identifier. Examples include class, public, static, void, return.
  8. Distinguish between:
    a) source code and object code: Source code is the program written in a high-level language. Object code is the program that is in low-level language, generated after compiling the source code.
    b) compiler and interpreter: Compiler is a program that converts high-level language program into low-level language program at once. Interpreter is a program that converts high-level language program into low-level language program line by line.
    c) JDK 1.3 and BlueJ: JDK 1.3 is the toolkit that includes the compiler, interpreter and other libraries needed to compile and run Java programs. BlueJ is an IDE that helps us in writing, compiling and executing Java programs all in one place.
  9. A compiler is specific to a language. Give your comments.
    A compiler converts high-level language program into low-level language program. This low-level language program consists of machine language which is specific to a given platform. It is machine dependent. This is why a compiler is specific to a language.
  10. What is the basic format of a Java program? Explain with an example.
    The basic format is to enclose the code within a class. Inside a class, we provide data members, and methods that work on those data members.
  11. What is BlueJ?
    BlueJ is an IDE that helps us in writing, compiling and executing Java programs all in one place.
  12. Mention five features of BlueJ.
    a) It is a window-based program, making it suitable to use.
    b) It has facilities for easier debugging.
    c) It highlights the syntax that makes the program easier to read.
    d) It allows compilation, execution, editing of programs all in one place.
  13. Name a package that is invoked by default.
    java.lang package.
  14. What are the points to be taken care while naming a class in a Java program?
    The class name must not be a keyword. It should be meaningful and relevant to the program. It should follow the naming rules that are used with identifiers.
  15. Java is a case-sensitive language. Explain.
    Java is a case-sensitive language because while naming identifiers, the uppercase and lowercase characters are treated differently. For example, int num = 5; and int Num = 7; both the variables are different.
  16. The main() function in a Java program is declared as:
    public static void main(String args[])
    What is the significance of the words public, static and void?
    The keyword public makes the function main() accessible from anywhere. The static keyword makes it possible to execute main() without the need of the object of the class in which it is defined. The void keyword states that main() doesn’t return any value.
  17. What does the term compilation mean?
    Compilation is the process of converting a high-level language program into a low-level language program at once.
  18. Java programs uses compiler as well as an interpreter. Explain.
    Java uses a compiler to generate an intermediate code called bytecode which becomes platform independent. Then Java uses an interpreter to execute this bytecode.
  19. Design a program in Java to display the following information on the output screen:
    Name:
    Class:
    Roll No.:
    Subject:
    School:

    class Info{
        public static void main(String args[]){
            System.out.println("Name: Peter Parker");
            System.out.println("Class: IX");
            System.out.println("Roll No. 18");
            System.out.println("Subject: Computer Application");
            System.out.println("School: My School");
        }
    }
  20. You have to display your bio-data on the output screen. Write a program in Java to perform the task in the given format:
    Name:
    Father’s Name:
    Date of birth:
    Blood Group:
    Aadhar Card No.
    State:

    class BioData{
        public static void main(String args[]){
            System.out.println("Name: Bruce Wayne");
            System.out.println("Father\'s Name: Thomas Wayne");
            System.out.println("Date of Birth: 01/01/2005");
            System.out.println("Blood Group: B+");
            System.out.println("Aadhar Card No.: 1234 5678 9012");
            System.out.println("State: West Bengal");
        }
    }

21 thoughts on “Introduction to Object Oriented Programming Concepts

  1. A very best website where the students can learn java programming, A very high level language.

  2. Sir,
    In order to perform any mathematical function in JAVA, which package is used, java.lang or java.math?

    • COBOL – Common Business Oriented Language.
      FORTRAN – Formula Translator
      Function Overloading is an example of polymorphism. It is about having same function, doing different types of tasks based on the values passed to it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.