Results 1 to 2 of 2
  1. #1
    squathub is offline Member
    Join Date
    Oct 2015
    Posts
    3
    Rep Power
    0

    Default Cannot link object to class

    Hi,

    I am trying to understad objects but do not know how to link an object to a class. I have tried to add a constructor but to no avail. Heres my code thanks

    Java Code:
    import java.util.Scanner;
    
    public class bananas {
    
    	public tuna(String average){
    		total/10 = average;
    		
    	
    	Scanner input = new Scanner(System.in);
    	int total = 0;
    	int grade;
    	int average;
    	int counter =0;
    	
    	while (counter < 10){
    		grade = input.nextInt();
    		total = total + grade;
    		counter++;
    	}
    	average = total/10;
    	System.out.println("Your average is:" +average);
    
    }
    		}
    Java Code:
    class tuna{
    
    public static void main (String []args){
    	
    	bananas myBananas = new bananas();
    	myBananas.saying();
    
    }
    }

  2. #2
    squathub is offline Member
    Join Date
    Oct 2015
    Posts
    3
    Rep Power
    0

    Default Re: Cannot link object to class

    This has been resolved. I basically created a constructor
    //Constructor
    public Pears(){

    and create an object in the main Pears myPears = new Pears();

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2014, 04:53 PM
  2. Replies: 3
    Last Post: 05-02-2011, 04:37 AM
  3. how to send a link through action class in struts
    By Kadiyala in forum New To Java
    Replies: 0
    Last Post: 02-17-2011, 07:44 AM
  4. how to link an object to a JButton
    By Twistx77 in forum New To Java
    Replies: 8
    Last Post: 11-16-2010, 08:42 PM
  5. How to create main class link to another two class?
    By pearllymary78 in forum New To Java
    Replies: 6
    Last Post: 07-16-2008, 11:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •