TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Monday, 16 December 2019

classes and objects in java example programs | class in javatpoint

Class in Java

    
  order:

1.    Modifiers : A class can be public or has default access (Refer this for details).

2.    Class name: The name should begin with a initial letter (capitalized by convention).

3.    Superclass(if any): The name of the class’s parent (superclass), if any, preceded by the keyword extends. A class can only extend (subclass) one parent.

4.    Interfaces(if any): A comma-separated list of interfaces implemented by the class, if any, preceded by the keyword implements. A class can implement more than one interface.

5.    Body: The class body surrounded by braces, { }.

Constructors are used for initializing new objects. Fields are variables that provides the state of the class and its objects, and methods are used to implement the behavior of the class and its objects.
There are various types of classes that are used in real time applications such as nested classesanonymous classeslambda expressions.
A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It can't be physical.
A class in Java can contain:

  • Fields
  • Methods
  • Constructors
  • Blocks
  • Nested class and interface

class in javatpoint
class in java programming

  

class in java programming

Syntax:

class<class_name>
{
field;
methods;
}
    
    ·       Using new keyword : It is the most common and general way to create object in java.

 Example:

//creating object of the  classTest

Test t=new test();

·       Using Class.forName(String className) method : There is a pre-defined class in java.lang package with name Class. The forName(String className) method returns the Class object associated with the class with the given string name.We have to give the fully qualified name for a class. On calling new Instance() method on this Class object returns new instance of the class with the given string name.

Example:

//creating object of public class Test
//consider class test present in com.pI package
Test obj=(Test)Class.forname(“com.pi.Test”).newInstance();

No comments:

Post a Comment