Three classes and two classes have method to print message

Method to instantiate two instances, one from the class Thought, and t

Page 1 of 1

5 Replies - 792 Views - Last Post: 21 July 2009 - 06:17 PM Rate Topic: -----

#1 tenec  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 22-February 09

Three classes and two classes have method to print message

Posted 21 July 2009 - 08:46 AM

trying to define three classes, named Thought, Advice and Message.
Thought and Advice each have a method that prints a message,
Advice extends Thought.
Message should contain main method, within which should create one instance of Advice, and one instance of Thought. I"m trying to (within the class Messages) create a Method to instantiate two instances, one from the class Thought, and the other from the class Advice, then invoke the two instances message methods separately but I'm stuck.

This is where I am so far with code:

public class  Message
	{
	   
		  public static void main( String args[] )
		  {
			 System.out.println( "I'm a teacher.\n" );
		 
			 System.out.println( "I'm your student." );
			 
			 }
	 	  
	 }


This is class Thought:

public class Thought
	{
	   public static void main( String[] args )
	   {
		 System.out.println( "I'm a teacher." );
		 

		}
	 } 

This is class advice:


// method message of the class Advice to
// print out different message Im your student.


public class Advice extends Message
{
public static void main( String args[] )
{
System.out.println( "I'm your student." );


}
}[code]

Any help or suggestions is welcome and appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Three classes and two classes have method to print message

#2 tenec  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 22-February 09

Re: Three classes and two classes have method to print message

Posted 21 July 2009 - 09:00 AM

Trying to define three classes, named Thought, Advice and Message.
Thought and Advice each have a method that prints a message,
Advice extends Thought.
Message should contain main method, within which should create one instance of Advice, and one instance of Thought. I"m trying to (within the class Messages) create a Method to instantiate two instances, one from the class Thought, and the other from the class Advice, then invoke the two instances message methods separately but I'm stuck.

This is where I am so far with code:

public class  Message
	{
	   
		  public static void main( String args[] )
		  {
			 System.out.println( "I'm a teacher.\n" );
		 
			 System.out.println( "I'm your student." );
			 
			 }
	 	  
	 }



This is class Thought:

public class Thought
	{
	   public static void main( String[] args )
	   {
		 System.out.println( "I'm a teacher." );
		 

		}
	 } 






This is class Advice
	   
 	
	public class Advice extends Message
	{
	   public static void main( String args[] )
	   {
		 System.out.println( "I'm your student." );
		 
		 
		}
	}



Each one of these compile and run fine but I I'm not clear on whether this is what is being asked for as per the instructions.
Any help or suggestions is welcome and appreciated.
Was This Post Helpful? 0
  • +
  • -

#3 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Three classes and two classes have method to print message

Posted 21 July 2009 - 09:05 AM

have both isntances as instance variables in your class..then create that method that instantiates them, maybe you could do it in the constructor
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Three classes and two classes have method to print message

Posted 21 July 2009 - 09:07 AM

it wont work with the main method...main method is not inherited..and dont double post
Was This Post Helpful? 0
  • +
  • -

#5 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Three classes and two classes have method to print message

Posted 21 July 2009 - 11:10 AM

You don't even have to extends Message or anything like that. You need to create an instance of each of those classes in the main method of the Advice class.

And yeah. Use a different method name than main. That will avoid some confusion.

Hope this helps! :)
Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Three classes and two classes have method to print message

Posted 21 July 2009 - 06:17 PM

duplicated topics merged
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1