Question about excercise 3.7.2

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
niiels93
Posts: 5
Joined: Thu Aug 06, 2020 3:41 pm
Contact:

Question about excercise 3.7.2

Post by niiels93 »

Hello!

i dont understand the question from chapter 3: "working with java data types" excercise 2.

The question:
Create a TestClass that has a static variable of type Bird. Initialize this variable with a valid Bird object.
Print out the default values of static and instance variables of Bird from the main method ofTestClass.
Also print out the static variable of TestClass from main. Observe the output

below my code:

Code: Select all

public class Bird{
	private boolean fly;						// instance variable
	private double speed;					// instance variable
	private float height;						// instance variable
	public static String name = "Sparrow";		// static class variable
	public static int wings = 2;					// static class variable
	
	
	// instance method setter
	public void isFly(){
		this.fly = true;
	}
	
public static void main(String [] args){
	Bird bd = new Bird();
	TestClass TC = new TestClass(bd);
}
}

class TestClass{
	public static Bird secondBird;
	public static void main (String [] args){
		
	}
}
if i want to compile this in cmd ill get an error:

required: no arguments
found: Bird
reason: actual and formal argument lists differ in length
1 error

I dont understand why i'll get an error, because i'm using the constructor to initialize the static variabele while parsing an object Bird to the instance TC?

Tnx in advance!

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Question about excercise 3.7.2

Post by admin »

You are doing TestClass TC = new TestClass(bd);, which means you are passing argument bd to TestClass's constructor. But in the code that you have shown, TestClass doesn't have a constructor.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 28 guests