public class P
{
public boolean m1(double a){
System.out.println("m1 from P "+a);
return true;
}
public int m2(int a){
System.out.println("m2 from P "+a);
return a;
}
public double m3(double a){
System.out.println("m3 from P "+a);
return a;
}
public static void main(String[] args) {
C c=new C();
P p=new P();
c.m1(10E7);
c.m1(10);
c.m2(10E7);
c.m2(10);
c.m3(10);
c.m3(10E7);
c.m4(10E7);
}
}
class C extends Main{
public boolean m1(double a){
System.out.println("m1 from C "+a);
return true;
}
public double m2(double a){
System.out.println("m2 from C "+a);
return a;
}
public int m3(int a){
System.out.println("m3 from C "+a);
return a;
}
public double m4(double a){
System.out.println("m4 from C "+a);
return a;
}
}
Consider the above program
The list of methods available for C class are below
1. m1(double) - Not inherited from Parent .It is the child class method.Because it overrides the one present in parent.
2. m2(int) -Inherited from parent class.Since the argument in the child class is different datatype for m2 ,this wont be overriden
3.m2(double) -Brand new method from child class.same reason as step 2
4. m3(double) - From parent class P. since the argument data type is different for the m3 method in child it wont be overriden
5.m3(int) -Brand new method in child class. Same reason as above
6. m4(double) -Since its a new method present only in child class it is called from child class only
How many methods are effectively present in class C? In other words, if you have an...
How can help me to create this program?
PartADriver
public class PartADriver
{
public static void main (String [] args)
{
// create two martians
Martian m1 = new Martian();
Martian m2 = new Martian("Grey", 3);
// display both martians
Output.showMessage("After instantiation.\n" +
"Martian #1: " + m1.toString() +
"\nMartian #2: " + m2.toString());
// make the first martian speak 3 times
for (int count = 0; count < 3; count++)
m1.speak();
// make the second martian...
1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); a.add(new Integer(7)); System.out.println(b.size()); A)1 B)2 C)3 D)4 E)5 2. Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code: Person p1, p2, p3; int m1, m2, m3; p1 = new Person(); m1 = p1.getMoney(); // assignment 1...
You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must contain: getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user may press Cancel or enter an empty string to...
You will write a class called Shoe.java Shoe.java should have Three instance variables String brand (cannot be blank) double size (from 5 to 12) int color (a number from 1 to 5 representing one of 5 colors) This code is to control the amount of colors. the colors represented are as follows 1. red 2. green 3. blue 4. black 5. grey One constructor, one get method per instance variable, one set method per instance variable. You will need a...
Please try your best to complete this 11 methods under. I have provided the UndirectedGraph class with the single instance data variable. Do not add any additional instance data variables. Do not modify any other classes provided. In addition to writing the 8 required methods of the interface and the constructor, you will also write methods for the two traversals and an isConnected method. import java.util.Queue; public class UndirectedGraph<T> implements BasicGraphInterface <T> { private DirectedGraph digraph; ...
Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...
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...
In Lab 5, you completed the MyRectangle class, which is a simple representation of a rectangle. Review Lab 5 before completing this lab and retrieve the MyRectangle class that you completed for this lab, since you will need it again in this lab. Before starting this lab, edit your MyRectangle class in the following way: • change the declaration of your instance variables from private to protected This will enable access of these variables by your MySquare subclass. Here is...
JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...
Take your MonthDay class from Assignment #6 and modify it to throw an IllegalArgumentException when the user of the class attempts to pass an invalid value for month and year. Make sure you have your main method(function) in a separate source file demonstrating use of the try/catch block to catch the IllegalArgumentException that the MonthDay class may throw in the event of an invalid month, or year. class MonthDays { private int month; private int year; public MonthDays(int aMonth, int...