Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java class types - what do they mean?

Tags:

java

types

What is the java class type used for? I am confused about what it means and how it is different than declaring an object type:

Class className;

Thanks

like image 809
greg Avatar asked Feb 15 '10 19:02

greg


People also ask

What does class type mean in Java?

A class in Java is a template that is used to create and define objects, object data types, and methods. Classes as a whole are categories and objects are items within each category. A class declaration constitutes of the following parts: Modifiers. Class name.

What are classes types?

In computer science, a type class is a type system construct that supports ad hoc polymorphism. This is achieved by adding constraints to type variables in parametrically polymorphic types.

How many class types are there in Java?

There are five kinds of classes: package-level , nested top-level , member , local , or anonymous . (The last four kinds are called inner classes . * A throw-away class that illustrates the five kinds of Java classes.


1 Answers

There are several uses for a Class object. For example, say I want to create an instance of a class based on some class name stored in a config file.

String className = config.myClass;
Class clazz = Class.forName(className);
Object myClassInstance = clazz.newInstance();
like image 103
Randy Simon Avatar answered Sep 22 '22 01:09

Randy Simon