The document contains 4 programming questions:
1) It asks to create a Student class with name, age, and mark data fields and a status method to check if the mark is passing or failing. It then asks to create an object and print the student information and status.
2) The first question asks about the instance variables in a sample IdentifyMyParts class and predicts the output of some sample code. The second asks what is wrong with a provided Rectangle class code. The third asks to write code to initialize and display values of variables in a NumberHolder class. The fourth predicts the output of a TestClass code.
3) It provides a Rectangle class with width, length, area, and perimeter methods
The document contains 4 programming questions:
1) It asks to create a Student class with name, age, and mark data fields and a status method to check if the mark is passing or failing. It then asks to create an object and print the student information and status.
2) The first question asks about the instance variables in a sample IdentifyMyParts class and predicts the output of some sample code. The second asks what is wrong with a provided Rectangle class code. The third asks to write code to initialize and display values of variables in a NumberHolder class. The fourth predicts the output of a TestClass code.
3) It provides a Rectangle class with width, length, area, and perimeter methods
The document contains 4 programming questions:
1) It asks to create a Student class with name, age, and mark data fields and a status method to check if the mark is passing or failing. It then asks to create an object and print the student information and status.
2) The first question asks about the instance variables in a sample IdentifyMyParts class and predicts the output of some sample code. The second asks what is wrong with a provided Rectangle class code. The third asks to write code to initialize and display values of variables in a NumberHolder class. The fourth predicts the output of a TestClass code.
3) It provides a Rectangle class with width, length, area, and perimeter methods
Design a class named Student to represent a student information. The
class contains: • A string data field named studName that specifies the student name. • An integer data field named studAge that specifies the student age. • A double data field named mark that specifies the student mark. A method named status which returns “Pass” if the mark is greater than or equal 60, otherwise it returns “Fail”
Create an object of the previous class Student and print student
information, and call the method status to print weather the student is passes or failed. 2) Questions: 1. Consider the following class: public class IdentifyMyParts { public int x = 7; public int y = 3; } a) What are the instance variables? b) What is the output from the following code: IdentifyMyParts a = new IdentifyMyParts(); IdentifyMyParts b = new IdentifyMyParts(); a.y = 5; b.y = 6; a.x = 1; b.x = 2; System.out.println("a.y = " + a.y); System.out.println("b.y = " + b.y); System.out.println("a.x = " + a.x); System.out.println("b.x = " + b.x); 2. What's wrong with the following program? public class SomethingIsWrong { public static void main(String[] args) { Rectangle myRect; myRect.width = 40; myRect.height = 50; System.out.println("myRect's area is " + myRect.area()); } }
3. Given the following class, called NumberHolder, write some code
that creates an instance of the class, initializes its two member variables, and then displays the value of each member variable. public class NumberHolder { public int anInt; public float aFloat; } 4. Predict the output of following Java program? class Test { int i; } public class TestClass { public static void main(String[] args) { Test t; System.out.println(t.i); } } 1) Write an output of the following class: public class Rectangle { double width, length; double Area ( ){ double a= width*length; return a; } double perimeter( ){ return 2* width + 2*length; } public static void main(String [ ] aregs){ Rectangle r1= new Rectangle (); r1.width=2; r1.length=3; System.out.println("r1 Area = "+r1.Area()); System.out.println("r1 Perimeter = "+r1.perimeter()); Rectangle r2 = new Rectangle(); r2.width=5; r2.length=4; System.out.println("Width of r2 = "+r2.width); System.out.println("Length of r2 = "+r2.length); System.out.println("r2 Area = "+r2.Area()); System.out.println("r2 Perimeter = "+r2.perimeter()); } } 2) Analyze the following code: public class Test { public static void main(String[] args) { double radius; final double PI= 1.0; double area = radius * radius * PI; System.out.println("Area is " + area); } } a. The program has compile errors because the variable radius is not initialized. b. The program has a compile error because a constant PI is defined inside a method. c. The program has no compile errors but will get a runtime error because radius is not initialized. d. The program compiles and runs fine.
Python Advanced Programming: The Guide to Learn Python Programming. Reference with Exercises and Samples About Dynamical Programming, Multithreading, Multiprocessing, Debugging, Testing and More