Question

c. [3 marks] Given the following definition of the class MyClass, class MyClass { String s int z Myclass(int y) { z = y } } fa. [2 marks] Explain why the method random of the class Math is declared as static. 7 Computer Programming 1- Semester 2, 201

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

c)

i)

MyClass obj=new MyClass(20);

ii)

obj.s="value";

iii)

System.out.printf("%s%d",obj.s,obj.z);

Note: Brother According to HomeworkLib's policy we are only allowed to answer first part if there are many. So, I request you to post other part as separate posts

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
c. [3 marks] Given the following definition of the class MyClass, class MyClass { String s...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Explain in detail what the code below does: public class MyClass {       public static void...

    Explain in detail what the code below does: public class MyClass {       public static void main(String args[]) {              System.out.println(isUniqueChars("something"));       }       public static boolean isUniqueChars(String str) {             int checker = 0;                                                                                               for (int i = 0; i < str.length(); ++i) {                         int val = str.charAt(i) - 'a';                         if ((checker & (1 << val)) > 0) return false;                         checker |= (1 << val);             }             return true;...

  • What is the missing keyword in the program below? public class Batman { public static int...

    What is the missing keyword in the program below? public class Batman { public static int minFunction(int n1, int n2) { int min; if (n1 > n2) min = n2; else min = n1; return min; //This is the value that will be returned from the minFunction method. //The value after the keyword return must match the return type from the method header. Ours is OK because they are both int. } // end the public method named minFunction }...

  • need java code for this question Question 2 (15 marks) (a) Does the following class successfully...

    need java code for this question Question 2 (15 marks) (a) Does the following class successfully compile? Explain your answer. public class MyClass public static void main(String arge) if(Integer.parseInt(args[0]) < 0) throw new RuntimeException(); C { 1 } If the class does compile, describe what will happen when we run it with command: java MyClass -10 (5 marks) (b) Write a complete definition of the method with the heading given below: public static double calculate insurance Premium double carValue, int...

  • C++ This exercise will introduce static member variables and static methods in class to you. Class...

    C++ This exercise will introduce static member variables and static methods in class to you. Class Department contain information about universities departments: name students amount in addition it also stores information about overall amount of departments at the university: departments amount class Department { public: Department(string i_name, int i_num_students); ~Department(); int get_students(); string get_name(); static int get_total(); private: string name; int num_students; static int total_departments; }; Carefully read and modify the template. You have to implement private static variable "total...

  • GIVEN CODES *****Boat.java***** import java.util.HashSet; import java.util.Set; public class Boat { private String name; //private instance...

    GIVEN CODES *****Boat.java***** import java.util.HashSet; import java.util.Set; public class Boat { private String name; //private instance variable name of type String private String boatClass; //private instance variable boatClass of type String private int regNum; //private instance variable regNum of type int private Set<String> crew = new HashSet<String>(); public void setName(String name) { this.name = name; } public void setBoastClass(String boatClass) { this.boatClass = boatClass; } public void setRegNum(int regNum) { this.regNum = regNum; } public String getName() { return name;...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • Question 27 1 pts Consider the following code: public class MyClass<T> { [... body of the...

    Question 27 1 pts Consider the following code: public class MyClass<T> { [... body of the class definition ...] } which of the following are legitimate lines of code in the body of the class definition? public T returnThis(T in) { řēturn īn; public double doubleInTin)*{, a. 'řēturn in.dõubtēvatue } 2. public T1 value; public void. doybleIn(T in) { rētuřň in } Question 28 1 pts Which of the following are items worth testing? all of the listed choices instance...

  • Python Write the definition of a class Counter containing: An instance variable named counter of type...

    Python Write the definition of a class Counter containing: An instance variable named counter of type int An instance variable named limit of type int. A constructor that takes two int arguments and assigns the first one to counter and the second one to limit A method named increment. It does not take parameters or return a value; if the instance variable counter is less than limit, increment just adds one to the instance variable counter. A method named decrement....

  • For C++ This is the information about the meal class 2-1. (24 marks) Define and implement...

    For C++ This is the information about the meal class 2-1. (24 marks) Define and implement a class named Dessert, which represents a special kind of Meal. It is to be defined by inheriting from the Meal class. The Dessert class has the following constructor: Dessert (string n, int co) // creates a meal with name n, whose type // is "dessert" and cost is co The class must have a private static attribute static int nextID ; which is...

  • Java Programming [20 marks] 3. (a Assume the following code has been implemented: public class ManipulateNames public s...

    Java Programming [20 marks] 3. (a Assume the following code has been implemented: public class ManipulateNames public static void main (String arqs) ( new Names ( Names myNames myNames.addName ("Thato"); myNames.addName ("Joe ") ; myNames.addName ("Susan") ; Page 2 of ?? Mobile Computing June 2016 COMS2013 myNames.addName ("James") ; myNames.printName (); int index-myNames.find ("Susan"); The Names class uses LinkedList object to store student names. The find method returns the position of the specified String in the LinkedList. Write [10 marks]...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT