PDF Google Drive Downloader v1.1


Report a problem

Content text OOP - 2022S Paper Solution.pdf

OOP Summer 2022 GTU Paper Solution :-) Question 1 (a) List out features of Java. Explain any two features. Java is a popular programming language that was developed in the mid-1990s by Sun Microsystems (now owned by Oracle Corporation). Some of the key features of Java are: 1. Platform Independence 2. Object-oriented 3. Security 4. Portability 5. Garbage Collection Two key features of Java are: 1. Platform Independence – Java code can run on any platform that supports the Java Virtual Machine (JVM). This makes it easy to develop and deploy software that can run on multiple platforms without the need for recompilation. For example, a Java program written on a Windows machine can be run on a Linux or Mac machine without any changes to the code. 2. Object-oriented – Java is an object-oriented programming language, which means that it supports encapsulation, inheritance, and polymorphism. This makes it easy to write modular and reusable code. Object-oriented programming allows developers to break down complex problems into smaller, more manageable pieces. This makes it easier to develop, test, and maintain software over time. (b) Write a single program which demonstrates the usage of following keywords: i) import, ii) new, iii) this, iv) break, v) continue Show how to compile and run the program in java. Here’s an example program that demonstrates the usage of the keywords import, new, this, break, and continue:
Explanation:  import java.util.Scanner; – This line imports the Scanner class from the java.util package, which is used to read user input from the console.  new Example(num); – This line creates a new instance of the Example class using the new keyword.  this.count = count; – This line uses the this keyword to refer to the current instance of the Example class and assigns the count parameter to its count field.  break; – This keyword is used to break out of a loop or switch statement.  continue; – This keyword is used to skip to the next iteration of a loop.
To compile and run this program, follow these steps: 1. Save the code as a file with a .java extension (e.g. Example.java). 2. Open a command prompt or terminal window and navigate to the directory where the file is saved. 3. Compile the program by typing javac Example.java and pressing Enter. 4. Run the program by typing java Example and pressing Enter. (c) Demonstrate use of try-catch construct in case of hierarchical Exception Handling. (i.e handling various exception belongs to the exception hierarchy) Explanation:  In this example, we have intentionally tried to divide an integer by zero, which will throw an ArithmeticException.  We have used a try block to wrap the code that might throw an exception.  We have used multiple catch blocks to handle different types of exceptions. The first catch block handles ArithmeticException, the second catch block handles RuntimeException, and the third catch block handles all other types of exceptions that are subclasses of the Exception class.  If an exception is thrown, the appropriate catch block will be executed based on the type of exception. In this case, the first catch block will be executed, and the message “Caught ArithmeticException: / by zero” will be printed to the console.
Question 2 (a) Explain following Java keywords using appropriate examples: i) static, ii) final, iii) super Super :- “super” is a keyword in Java that is used to refer to the superclass of the current object. It is used to call the superclass constructor, access the superclass’s methods, or access the superclass’s variables. Static:- “static” is a keyword in Java that is used to define a variable, method or block as a class-level entity. A static variable or method is associated with the class and not with any particular instance of that class. Static members are initialized only once when the class is loaded into memory.

Related document

x
Report download errors
Report content



Download file quality is faulty:
Full name:
Email:
Comment
If you encounter an error, problem, .. or have any questions during the download process, please leave a comment below. Thank you.