Home Why can't I make this (SectionsPagerAdapter) class private?
Reply: 1

Why can't I make this (SectionsPagerAdapter) class private?

M. Warren
M. Warren Published in 2018-02-13 17:25:40Z
private class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {

    public int getCount () {
        return 4;


I am doing a Head First Android tutorial and I cannot make this class private? Is there a different way to do this on android? Should I add parameters for the super class?

Michael Dodd
Michael Dodd Reply to 2018-02-13 17:32:59Z

Classes that are self-contained within their own file cannot be declared private as they cannot be accessed by any other class, effectively rendering them useless. The only time a class can be declared private is if it is a child of another class e.g.

public class ClassA {
    private ClassB myInstance = new ClassB();

    private class ClassB {
        public ClassB() {}

In this case, ClassB is only visible to ClassA, and can only be used by ClassA. If your class is self-contained in its own file, the maximum privacy it can have is package-private i.e. no specifier:

package com.example.myPackage;

class ClassB {
    ClassB() { }

In this case, ClassB can only be accessed and instantiated by any other class contained within the com.example.myPackage package.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.337954 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO