Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:33:39+00:00 2026-05-24T08:33:39+00:00

I know how to do it in java but im stubling in objetice-c In

  • 0

I know how to do it in java but im stubling in objetice-c

In java I would have an interface like this:

public interface Car {
    public void startCar();
}

and the a class which would implement this interface:

public class SomeCarImpl implements Car {
   public void startCar() {
      System.out.println("starting the car...");
   }
}

and now I would be able to this in my main class

public void MainClass {
   public static void main(String [] args) {
       Car myCar = new SomeCarImpl();
       car.startCar();
   }
}

Now here I’m getting in trouble in objective-c. The first two things are easily made with protocols but when I want to call it like this, nothing happens

//header
id <Car> *myCar;

//instance
myCar = [[SomeCarImpl alloc] init];

//calling and nothing happens
[myCar startCar];

I hope you can understand my problem…and help me 🙂

//edit here is the code

@interface SomeCarImpl:NSObject<Car>
@end

@implementation SomeCarImpl
-(void)startCar{
NSLog(@"run");
}
@end  

@protocol Car <NSObject>
-(void)startCar;
@end



@interface DetailViewController:UIViewController<UISplitViewControllerDelegate> {
IBOutlet UIButton *runButton;
id<Car> myCar;
}
@property(strong, nonatomic)IBOutlet UIButton *runButton;
@property(strong, nonatomic)id<Car> myCar;
@end

and finally (detailViewController.myCar = [[SomeCarImpl]alloc]init] is called in the tableView beforehand)

-(IBAction)runButton:(id)sender {
[myCar startCar];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:33:40+00:00Added an answer on May 24, 2026 at 8:33 am

    Your Java code would vaguely translate into something like this:

    //public interface Car {
    //    public void startCar();
    //}
    
    @protocol Car
    - (void)startCar;
    @end
    
    //public class SomeCarImpl implements Car {
    //    public void startCar() {
    //        System.out.println("starting the car...");
    //    }
    //}
    
    @interface SomeCarImpl : NSObject<Car>
    
    @end
    
    @implementation SomeCarImpl
    
    - (void)startCar {
        NSLog(@"starting the car...");
    }
    
    @end
    
    // Car myCar = new SomeCarImpl();
    // car.startCar();
    id<Car> myCar = [[SomeCarImpl alloc] init];
    [myCar startCar];
    

    In your ObjC code, you need to remove the asterisk from this line:

    id <Car> *myCar;
    

    Because the type id is already a pointer (although I don’t think this is not the root of your problem).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the knowledge of C++ template, but don't know Java. Would someone explain
I Know there's a Vector class in java, but it seems to be just
First of all, I know how to build a Java application. But I have
I have always liked the documentation on Java APIs, generally speaking, but I know
i wanted to develop a whiteboard application..i know the basics of java..but have no
i know virtually no java but i'm trying to learn some for this project.
I know how to use casting in Java but have a more specific question;
I know similar questions have been asked before but i think this is slightly
I would like to know that if java/scala has the string object that could
[Yes I have seen this question but I do not know C nor C++,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.