Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Initializing an obect

$
0
0
I am studying for an exam. Would you please let me know what I am doing wrong.

/*Write a class called "Cat". Invent a few "instance variables" that make sense for a Cat.
* Include a constructor that allows the user to specify values for all of the instance
* variables at the moment the Cat object is instantiated (created).
* Include a toString method that produces a String representation of the state of the Cat.
* Include an equals method that makes sense to you.
* Write some other methods (behaviors) that Cats should be able to do.
* Make sure that you have practiced some method(s) that require parameters to be passed in.
* Make sure that you have practiced some methods that return a value.
ANSWERS WILL VARY */



public class StudyExam {

	
	public static void main(String[] args) {
		 
		cat Cat1 = new cat(waska,  jumping, 12);
	}
}




public class Cat {
private String name;
private String talent;
private int age;

public void cat (String n, String t, int a){
	String name = n;
	String talent = t;
	int age = a;
	
	System.out.println(this);
}


@Override
public String toString() {
  return String.format("The name of the cat is" + name + " His talent is " + talent + "His age is" + age);
	}
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>