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 7782513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:34:05+00:00 2026-06-01T19:34:05+00:00

I dont understand why is that for example: class Test { public void someMethod()

  • 0

I dont understand why is that

for example:

class Test
{
   public void someMethod()
   {



   }

}

and then

Test test = new Test();

why is neccesary to write the type of the variable, so if you see that the variable assigns that custom class, i think that is some overflow writing).

ps: this is java, and i am new to it, so sorry if a quiestion is stupid, but i dont understand this moment

  • 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-06-01T19:34:07+00:00Added an answer on June 1, 2026 at 7:34 pm

    You’re declaring the type of the variable (reference), as distinct to the type of the object.

    e.g. your variable type could be Test, or it could be a supertype (Object), or an interface that Test implements. Which one you choose depends on how your clients should refer to the initialised object. e.g. should they know it’s a particular type, or is it sufficent (or desirable) that they only know it will implement a given interface, or subset of features.

    A better example would be:

    Animal animal = new Dog();
    

    in which your client code only knows that it’s dealing with an Animal. i.e. it can (say) call a method .eat(), but it won’t know that a Dog eats differently to a Fish.

    Note that some languages (e.g. Scala) will perform type inference. That is, you don’t have to declare the variable type, but rather the compiler will determine what type it should be from your subsequent usage of the variable. The resultant code is still statically typed, but the compiler does more work for you.

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

Sidebar

Related Questions

I am new to using numpy and one thing that I really don't understand
class Program { public delegate void VoidMethodDelegate(); public delegate int IntMethodDelegate(); static void Main(string[]
Considering such code: class ToBeTested { public: void doForEach() { for (vector<Contained>::iterator it =
I want to define a type name in a templated class that I can
C++ is considered statically typed. I understand that. I don't understand how that applies
I don't understand why authors said that Code Listing 9.1 from Programming in Scala
I understand that I can call ToString().IndexOf(...), but I don't want to create an
For some reason that I don't understand, when I create my SurfaceView from an
I don't understand why IList implements IEnumerable taking in consideration that IList implements ICollection
For some reason that I don't understand, video websites do not play when using

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.